-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
134 lines (112 loc) · 2.87 KB
/
index.html
File metadata and controls
134 lines (112 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
border: 0;
outline: 0;
}
.interval {
background-image: url(./Timer.png);
background-size: 100% auto;
background-repeat: no-repeat;
width: 261px;
height: 93px;
position: relative;
display: flex;
}
.interval>p {
font-family: number;
font-size: 50px;
transform: translateY(-10px);
user-select: none;
display: flex;
}
.interval>.black-text {
margin: auto;
}
.interval>.black-text>i {
font-style: normal;
color: rgba(255, 255, 255, .1);
text-shadow: 0 0 5px #031327;
}
.interval>.black-text>i.active {
color: white;
text-shadow: 0 0 5px #0078bc;
}
.interval>.black-text>span {
position: relative;
color: rgba(255, 255, 255, .1);
text-shadow: 0 0 5px #031327;
}
.interval>.black-text>span>span {
position: absolute;
color: white;
}
.interval>.black-text>span::after {
content: attr(data-number);
color: white;
position: absolute;
right: 0;
text-shadow: 0 0 5px #0078bc;
}
@font-face {
font-family: number;
src: url(./number-font.ttf);
}
</style>
</head>
<body>
<div class="interval">
<p class="black-text" data-string="123">
<span>0</span>
<span>0</span>
<i class="hourse">:</i>
<span>0</span>
<span>0</span>
<i class="minutes">:</i>
<span>0</span>
<span>0</span>
</p>
</div>
</body>
<script>
const time = 5; // 倒计时时间
const toDate = new Date();
toDate.setMinutes(toDate.getMinutes() + 5);
const inter = setInterval(() => {
const res = getTimeArray(toDate);
if (!res) return clearInterval(inter);
document.querySelectorAll('.black-text>span').forEach((item, i) => {
item.setAttribute('data-number', res[i]);
})
}, 1000);
const timeout = setTimeout(() => {
document.querySelector('.minutes').className += ' active';
clearInterval(timeout);
}, 1000);
//
function getNumbers(str) {
const temp = String(str);
if (str >= 10) return temp.split('');
if (str === 0) return [0, 0];
return [0, temp];
}
function getTimeArray(times) {
const currDate = new Date();
const resTime = (times.getTime() - currDate.getTime()) / 1000;
if (resTime <= 0) return null;
const days = Math.floor(resTime / 60 / 60 / 24);
const hourse = getNumbers(Math.floor(resTime / 60 / 60) % 24);
const minutes = getNumbers(Math.floor(resTime / 60) % 60);
const seconds = getNumbers(Math.floor(resTime % 60));
return ['', '', minutes, seconds].flat();
}
</script>
</html>