-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhref.html
63 lines (53 loc) · 2.38 KB
/
href.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 id="time">0</h1>
<script>
//数字自增到某一值动画参数(目标元素,自定义配置)
function NumAutoPlusAnimation(targetEle, options) {
/*可以自己改造下传入的参数,按照自己的需求和喜好封装该函数*/
//不传配置就把它绑定在相应html元素的data-xxxx属性上吧
options = options || {};
var $this = document.getElementById(targetEle),
time = options.time || $this.data('time'), //总时间--毫秒为单位
finalNum = options.num || $this.data('value'), //要显示的真实数值
regulator = options.regulator || 100, //调速器,改变regulator的数值可以调节数字改变的速度
step = finalNum / (time / regulator),/*每30ms增加的数值--*/
count = 0, //计数器
initial = 0;
var timer = setInterval(function() {
count = count + step;
if(count >= finalNum) {
clearInterval(timer);
count = finalNum;
}
//t未发生改变的话就直接返回
//避免调用text函数,提高DOM性能
var t = Math.floor(count);
if(t == initial) return;
initial = t;
$this.innerHTML = initial;
}, 30);
}
NumAutoPlusAnimation("time", {
time: 1000,
num: 15000,
regulator: 50
})
</script>
<!-- 待改进之处:应该是总时间不变,调速器应该根据真实数值和总时间来改变 -->
<script>
const arr = [];
for(var i = 0;i<100;i++){
arr.push(i)
}
console.log(arr[0],arr[1])
</script>
</body>
</html>