-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
79 lines (73 loc) · 2.49 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
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
<!--
#button1 {
width: 50px;
height: 50px;
border-radius: 50%;
border: none;
}
#progress {
width: 0px;
height: 50px;
background-color: black;
}
-->
</style>
</head>
<body>
<button id="button1">
<div id="sec"></div>
</button>
<div id="progress"></div>
<script>
(function(){
var LIMIT = 10;
var timer;
var count = 0;
var progressWidth = 0;
var button1 = document.getElementById('button1');
button1.oncontextmenu = function () {
return false;
}
var start = function () {
console.log("mousedown");
if (!timer) {
timer = setInterval(counter, 100);
}
}
var stop = function () {
console.log("mouseup");
clearInterval(timer);
timer = 0;
count = 0;
var sec = document.getElementById('sec');
sec.innerText = LIMIT;
var progress = document.getElementById('progress');
progressWidth = 0;
progress.style.width = progressWidth + 'px';
}
button1.addEventListener('mousedown', start, false);
button1.addEventListener('mouseup', stop, false);
button1.addEventListener('mouseout', stop, false);
var counter = function(){
console.log(count++);
var sec = document.getElementById('sec');
sec.innerText = LIMIT - count;
var progress = document.getElementById('progress');
progressWidth = progressWidth + 10;
progress.style.width = progressWidth + 'px';
if (count > 9) {
progress.style.width = '100px';
sec.innerText = 'OK';
clearInterval(timer);
timer = 0;
count = 0;
}
}
})();
</script>
</body>
</html>