-
Notifications
You must be signed in to change notification settings - Fork 47
/
test.html
64 lines (56 loc) · 1.9 KB
/
test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="dd" class="txt" style="height: 1500px;background-color:blue;">
<div id="yy"
style="position: absolute;left: 100px;top: 155px;width: 100px;height: 100px;background-color:#fff;"></div>
<input type="text" style="width: 300px;height: 30px" id="test">
</div>
</body>
<script src="build/comutils.min.js"></script>
<script>
var throttle = function throttle(fn) {
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
var _self = fn,
//需要被延迟执行的函数引用
timer = void 0,
firstTime = true; //是否第一次调用
return function () {
var _this = this;
var args = arguments;
if (firstTime) {
//第一次调用不用延迟
_self.apply(this, args);
firstTime = false;
}
if (timer) {
//timer还在没结束前一次
return false;
}
timer = setTimeout(function () {
//延迟执行
clearTimeout(timer);
timer = null; //手动释放timer
_self.apply(_this, args);
}, delay);
};
};
console.log(comutils.formatTime(new Date(),'yyyy年MM月dd日 hh-mm-ss'))
window.addEventListener('click',throttle(console11,4000))
function console11 () {
console.log(11)
}
setTimeout(function () {
comutils.scrollApi.scrollTo(300,600)
},1500)
document.getElementById('yy').addEventListener('click', comutils.debounce(function () {
console.log(11)
}, 1000))
console.log(comutils.secretInfo(13812333069))
console.log(comutils.prefixStyle('color'))
</script>
</html>