forked from yangxi0126/javaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
数字逐一停止.html
72 lines (53 loc) · 1.77 KB
/
数字逐一停止.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
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="num"></div>
</body>
<script src="../javaScript/checkbox/js/jquery-1.9.1.min.js"></script>
<script>
function showScore($ele, num, secand, pause){ //second 按照秒数,动画运行多少秒
if (!secand) { secand = 2;}
if (!pause) { pause = 20;}
var len = String(num).length;
var temnum, times = 0 , stepTimes, max ;
var numArr = String(num).split("");
function getRandom(n){
var num = Math.floor(Math.random()*(Math.pow(10, n)-1 - Math.pow(10, n-1))+Math.pow(10, n-1));
if (String(num).length !== n) {num = getRandom(n);}
return num;
}
function setValue(num, pause, secand){//second 运行多少秒后停止
var len = String(num).length, j=0;
if (!stepTimes) {
max = Math.ceil(secand*1000/len);
stepTimes = Math.ceil(max/pause);
}
temnum = "";
setTimeout(function(){
for (var i = 1; i <= len; i++) {
if (times >= stepTimes*i) {
j++;
temnum += numArr[i-1]+"";
}else{
break;
}
};
if (j < len) {
$ele.html(temnum+""+getRandom(len-j));
}else{
$ele.html(temnum);
}
if (times >= max || j >= len) {return;};
setValue(num, pause, secand);
times++;
}, pause);
}
setValue(num, pause, secand);
}
showScore($(".num"), 2344, 1.5, 10);
</script>
</html>