-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolling.html
52 lines (50 loc) · 927 Bytes
/
polling.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
#botton {
width: 100px;
height: 100px;
background: red;
}
</style>
<body>
<div id="botton">
click
</div>
<script type="text/javascript">
function polling(fn, wait) {
var flag = false,
time = 0;
return function(...agrs) {
if (flag || time) {
clearInterval(time);
time = null;
flag = false;
return
}
time = setInterval(function() {
flag = fn.apply(this, agrs);
console.log(flag)
if (flag) {
clearInterval(time);
time = null;
flag = false;
}
}, wait);
};
}
var poll = polling(function() {
return true
}, 1000)
let bot = document.getElementById('botton')
bot.onclick = function clickMe() {
let a=poll()
console.log(a, poll)
}
</script>
</body>
</html>