-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (46 loc) · 1.6 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>LTD</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css">
</head>
<body>
<script>
console.logRepeated = throttle(console.log);
function throttle(fnc, timeToWaitBeforeNextCall = 200) {
let timeoutId;
let timeStamp;
let nextScheduledCallTime;
let prevCallTime = 0;
return (...args) => {
nextScheduledCallTime = prevCallTime + timeToWaitBeforeNextCall;
timeStamp = performance.now();
if (!prevCallTime || timeStamp > nextScheduledCallTime) {
fnc(...args);
prevCallTime = timeStamp;
} else {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
fnc(...args);
prevCallTime = timeStamp;
}, timeToWaitBeforeNextCall - (timeStamp - prevCallTime));
}
};
}
function debounce(fnc, delay = 200, callImmediate = false) {
let timeoutId;
return (...args) => {
if (callImmediate && !timeoutId) {
fnc(...args);
}
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fnc(...args), delay);
};
}
</script>
<canvas id="canvas"></canvas>
<script src="build/main.js" type="module"></script>
</body>
</html>