-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
302 lines (271 loc) · 9.74 KB
/
index.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<!--Made with ❤ by XUANZHI-->
<!--该页面已接入百度统计-->
<html>
<head>
<meta charset="UTF-8">
<meta name="theme-color" content="#e9f1e9">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>简单计时器</title>
<!-- Bootstrap -->
<link href="https://unpkg.zhimg.com/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.staticfile.org/mdbootstrap/4.20.0/css/mdb.min.css">
<link href="./x-az.css" rel="stylesheet">
<style>
#m,
#s {
font-size: 120px;
}
#ms {
color: gray;
font-size: 80px;
}
.split {
color: gray;
display: inline-block;
transform: translateY(-15px);
font-size: 100px;
}
.timerTimeMore {
display: none;
}
@font-face {
font-family: num;
src: url('./number.otf');
}
#number {
font-family: num;
}
.infoLabel{
font-size: 20px;
color: gray;
}
/* 移动设备 */
@media (max-width: 767px) {
#m,
#s {
font-size: 80px;
}
#ms {
font-size: 60px;
}
.split {
font-size: 60px;
}
.infoLabel {
font-size: 16px;
}
}
</style>
<script>
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?76d748872de14bad7ef88266420d87e4";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<br class="brBefore">
<br class="brBefore">
<div class="container">
<div class="card glass"> <br>
<div class="container">
<h1 class="text-center" id="titleText">简单计时器</h1>
<div class="text-center" id="number">
<span id="m">00</span>
<span class="split">:</span>
<span id="s">00</span>
<span id="ms">0</span>
</div>
<button class="btn btn-success btn-block" id="mainBtn">开始</button>
<div class="row">
<div class="col-md-2 col-3">
<div class="mt-4 infoLabel text-center">
倒计时
</div>
</div>
<div class="col-md-2 col-2">
<div class="md-form">
<input type="number" class="form-control setTime" id="setM" value="0" min="0" max="99">
<label for="minNum">分</label>
</div>
</div>
<div class="col-md-2 col-2">
<div class="md-form">
<input type="number" class="form-control setTime" id="setS" value="0" min="0" max="59">
<label for="maxNum">秒</label>
</div>
</div>
<div class="col-md-6 col-5 text-center">
<button class="btn btn-light mt-3" id="resetBtn">重置</button>
</div>
</div>
<div class="text-center">
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="15">
15秒
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="30">
30秒
</button>
<button class="btn btn-light btn-sm timerTime" data-time="60">
1分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="120">
2分钟
</button>
<button class="btn btn-light btn-sm timerTime" data-time="300">
5分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="600">
10分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="900">
15分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="1200">
20分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="1800">
30分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="2400">
40分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="2700">
45分钟
</button>
<button class="btn btn-light btn-sm timerTime timerTimeMore" data-time="3600">
1小时
</button>
<button class="btn btn-light btn-sm" id="toggleTimer">更多</button>
</div>
</div>
<br>
</div>
</div>
<br>
<br>
<script src="https://unpkg.zhimg.com/jquery@3/dist/jquery.min.js"></script>
<script src="https://unpkg.zhimg.com/[email protected]/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/mdbootstrap/4.20.0/js/mdb.min.js"></script>
<script>
var mode = 1; //1为正计时,-1为倒计时
var time = 0;
var isRunning = false;
var timerInterval;
function changeMode(m) {
mode = m;
if (mode == 1) {
$("#titleText").fadeOut("", function () {
$("#titleText").text("秒表").fadeIn();
})
} else {
$("#titleText").fadeOut("", function () {
$("#titleText").text("倒计时").fadeIn();
})
}
}
setTimeout(function () {
changeMode(1);
}, 1000);
$("#toggleTimer").click(function () {
if ($(this).text() == "更多") {
$(this).text("更少")
.addClass("btn-success")
.removeClass("btn-light");
$(".timerTimeMore").fadeIn();
} else {
$(this).text("更多")
.addClass("btn-light")
.removeClass("btn-success");
$(".timerTimeMore").fadeOut();
}
});
function showTime() {
var ms = time % 10;
var s = Math.floor(time / 10) % 60;
var m = Math.floor(time / 600);
var sText = s < 10 ? "0" + s : s;
var mText = m < 10 ? "0" + m : m;
$("#ms").text(ms);
$("#s").text(sText);
$("#m").text(mText);
}
function setTime(sec) {
if (sec == 0) {
if (mode == -1) changeMode(1);
} else {
if (mode == 1) changeMode(-1);
}
time = sec * 10;
showTime();
}
$(".timerTime").click(function () {
$("#setM").val(Math.floor($(this).data("time") / 60));
$("#setS").val($(this).data("time") % 60);
setTime($(this).data("time"));
});
function setMinAndSec() {
var m = parseInt($("#setM").val());
var s = parseInt($("#setS").val());
if (isNaN(m)) m = 0;
if (isNaN(s)) s = 0;
setTime(m * 60 + s);
}
$(".setTime").on("input", setMinAndSec);
var sound = new Audio("./sound.mp3");
var pauseSound = new Audio("./pause.mp3");
function stopTiming(){
if (isRunning && mode == -1) {
setMinAndSec();
} else {
setTime(0);
$("#setM").val("0");
$("#setS").val("0");
}
if (isRunning) {
clearInterval(timerInterval);
isRunning = false;
$("#mainBtn").text("开始")
.addClass("btn-success")
.removeClass("btn-light");
}
}
$("#resetBtn").click(stopTiming);
function updataTime() {
time += mode;
if (time <= 0) {
stopTiming();
sound.play();
}
showTime();
}
$("#mainBtn").click(function () {
if (isRunning) {
clearInterval(timerInterval);
isRunning = false;
$(this).text("开始")
.addClass("btn-success")
.removeClass("btn-light");
pauseSound.play();
} else {
timerInterval = setInterval(updataTime, 100);
isRunning = true;
$(this).text("暂停")
.addClass("btn-light")
.removeClass("btn-success");
sound.currentTime = 0;
sound.play();
setTimeout(function () {
sound.pause();
}, 600);
}
});
</script>
</body>
</html>