-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettimeout.html
43 lines (34 loc) · 939 Bytes
/
settimeout.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
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
</head>
<body>
<div style="height: 20px;width: 400px;border: 1px solid gray;padding: 2px">
<div style="height:20px;width:0px;background-color: red;" id="div2">
</div>
</div>
<br />
<input type="button" value="开始" οnclick="doStart()" />
<input type="button" value="停止" οnclick="doStop()" />
<script type="text/javascript">
var timer = null;
var width = 0;
function doStart() {
timer = window.setTimeout(onChange(), 10);
}
function doStop() {
window.clearTimeout(timer);
}
function onChange() {
if(width == 400) {
window.clearTimeout(timer);
}else {
width += 1;
document.getElementById("div2").style.width = width + "px";
timer = window.setTimeout(onchange(), 10);
}
}
</script>
</body>
</html>