forked from zzzzzhowie/practical-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrottle.html
More file actions
57 lines (46 loc) · 1.1 KB
/
throttle.html
File metadata and controls
57 lines (46 loc) · 1.1 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.mouse_move {
display: inline-block;
background: blue;
width: 500px;
height: 500px;
margin: 20px;
}
span {
color: white;
}
button {
position: absolute;
left: 400px;
top: 400px;
}
</style>
<script src="./throttle.js"></script>
</head>
<body>
<div class="mouse_move">
<span>Throttle1</span>
</div>
<button>取消</button>
<div class="mouse_move">
<span>Proxy</span>
</div>
<script >
const TIME = 2000
function handler() {
console.log(1)
}
let throttledFunc = throttle(handler, TIME)
let btn = document.querySelector("button")
btn.onclick = throttledFunc.cancel
let mousemoveElementList = document.querySelectorAll('.mouse_move')
mousemoveElementList[0].addEventListener('mousemove', throttledFunc)
mousemoveElementList[1].addEventListener('mousemove', proxy(handler, TIME))
</script>
</body>
</html>