-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtimer.html
executable file
·248 lines (225 loc) · 7.2 KB
/
timer.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
#clock strong {
font-size: 150px;
text-align: center;
color:#013878;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" >
<table width="100%" height="100%" border="0" onmousedown="show('btn_tr')" style="cursor:pointer" >
<tr >
<td width="10%" height="150" align="left" valign="top"> </td>
<td width="80%"> </td>
<td width="10%" align="right" valign="top"> </td>
</tr>
<tr>
<td height="214"> </td>
<td align="center"><span id="clock"><strong>00:00:00</strong></span> </td>
<td> </td>
</tr>
<tr>
<td height="63"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3" ><table width="100%" border="0" height="122" >
<tr id="btn_tr" style="display:block" >
<td width="15%" height=""> </td>
<td width="70%" align="left" valign="bottom" >
时:
<input id="hinput" type="text" value="00" style="width:20px"/>
分
<input id="minput" type="text" value="00" style="width:20px"/>
秒
<input id="sinput" type="text" value="00" style="width:20px"/>
<br />
<input id="setB" type="button" value="设置" onclick="setTime()">
<input id="startB" type="button" value="开始" onclick="run()">
<input id="pauseB" type="button" value="暂停" onclick="pause()">
<input id="endB" type="button" value="停止" onclick="stop()">
<br />
<!--<input id="fullscreenB" type="button" value="FullScreen" onclick="fullscreen()">-->
<input id="hiddenB" type="button" value="隐藏控制面板" onclick="hid('btn_tr')">
<br>
<input id="clockHidden" type="hidden" value="00:00:00">
</td>
<td width="5%"> </td>
</tr>
</table></td>
</tr>
</table>
<!--
<input id="diff" type="text">
<input id="next" type="text">
-->
<script language="Javascript">
var normalelapse = 1000;
var nextelapse = normalelapse;
var counter;
var startTime;
//var start = clock.innerText;
var finish = "00:00:00";
var timer = null;
function fullscreen(){
var WshShell = new ActiveXObject('WScript.Shell')
WshShell.SendKeys('{F11}');
}
function pauseImage(){
pause();
image.innerHTML="<img src='start.png' onmousemove=\"this.src='startB.png'\" onmouseout=\"this.src='start.png'\" onclick='startImage();' style='cursor: pointer' title='Continue'/>";
}
function startImage(){
run();
image.innerHTML="<img onmousemove=\"this.src='pauseB.png'\" onmouseout=\"this.src='pause.png'\" src='pause.png' onclick='pauseImage();' style='cursor: pointer' title='pause'/>";
}
function show(id){
document.getElementById(id).style.display="block";
}
function hid(id){
document.getElementById(id).style.display="none";
}
function setTime(){
startB.disabled = false;
pauseB.disabled = true;
setB.disabled = false;
var s = sinput.value;
var m = minput.value;
var h = hinput.value;
if(isNaN(h) || isNaN(m) || isNaN(s)){
return;
}
var sn = new Number(s);
var mn = new Number(m);
var hn = new Number(h);
var ss = sn < 10 ? ("0" + sn) : s;
var sm = mn < 10 ? ("0" + mn) : m;
var sh = hn < 10 ? ("0" + hn) : h;
var init = sh + ":" + sm + ":" + ss;
clock.innerHTML = "<strong>"+init+"</strong>";
clockHidden.value = init;
window.clearTimeout(timer);
window.clearInterval(timer);
}
function reset(){
sinput.value = "00" ;
minput.value = "00" ;
hinput.value = "00" ;
}
// 开始运行
function run() {
startB.disabled = true;
pauseB.disabled = false;
setB.disabled = true;
endB.disabled = false;
counter = 0;
// 初始化开始时间
startTime = new Date().valueOf();
// nextelapse是定时时间, 初始时为100毫秒
// 注意setInterval函数: 时间逝去nextelapse(毫秒)后, onTimer才开始执行
timer = window.setInterval("onTimer()", nextelapse);
}
// 暂停
function pause() {
startB.disabled = false;
pauseB.disabled = true;
setB.disabled = false;
window.clearTimeout(timer);
}
//停止
function stop(){
startB.disabled = false;
pauseB.disabled = true;
setB.disabled = false;
endB.disabled = true;
sinput.value = "00" ;
minput.value = "00" ;
hinput.value = "00" ;
clock.innerHTML = "<strong>00:00:00</strong>"
clockHidden.value = "00:00:00";
window.clearTimeout(timer);
window.clearInterval(timer);
}
window.onload = function() {
pauseB.disabled = true;
}
// 倒计时函数
function onTimer()
{
if (clockHidden.value == finish)
{
window.clearInterval(timer);
clock.innerHTML = "<strong><font color=#013878>Time's up!</font></strong>"
startB.disabled = true;
pauseB.disabled = true;
setB.disabled = false;
endB.disabled = true;
return;
}
//var hms = new String(clock.innerText).split(":");
var hms = new String(clockHidden.value).split(":");
//var ms = new Number(hms[3]);
var s = new Number(hms[2]);
var m = new Number(hms[1]);
var h = new Number(hms[0]);
s -= 1;
if (s < 0)
{
s = 59;
m -= 1;
}
if (m < 0)
{
m = 59;
h -= 1;
}
var ss = s < 10 ? ("0" + s) : s;
var sm = m < 10 ? ("0" + m) : m;
var sh = h < 10 ? ("0" + h) : h;
//start = sh + ":" + sm + ":" + ss + ":" + ms;
var nowtime = sh + ":" + sm + ":" + ss;
clock.innerHTML = "<strong>"+nowtime+"</strong>";
//倒计时1分钟时时间变红色
if(s<=59 && m==0 && h==0){
//setTimeout("onTimer2()",200);//红色时间闪烁
clock.innerHTML = "<strong><font color=#bb0000>"+nowtime+"</font></strong>"
}
clockHidden.value = nowtime;
// 清除上一次的定时器
window.clearInterval(timer);
// 自校验系统时间得到时间差, 并由此得到下次所启动的新定时器的时间nextelapse
counter++;
var counterSecs = counter * 1000;
var elapseSecs = new Date().valueOf() - startTime;
var diffSecs = counterSecs - elapseSecs;
nextelapse = normalelapse + diffSecs;
//diff.value = counterSecs + "-" + elapseSecs + "=" + diffSecs;
//next.value = "nextelapse = " + nextelapse;
if (nextelapse < 0) nextelapse = 0;
// 启动新的定时器
timer = window.setInterval("onTimer()", nextelapse);
}
function onTimer2(){
var hms = new String(clockHidden.value);
clock.innerHTML = "<strong><font color=#8b0000>"+hms+"</font></strong>";
}
function fullscreen(){
var WsShell = new ActiveXObject('WScript.Shell')
WsShell.SendKeys('{F11}');
}
/*
function onTimer3(){
var hms = new String(clockHidden.value);
clock.innerHTML = "<strong><font color=#8b0000>"+hms+"</font></strong>";
}
*/
</script>
</body>
</html>