|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Title</title> |
| 6 | +</head> |
| 7 | +<body> |
| 8 | +<div class="num"></div> |
| 9 | +</body> |
| 10 | +<script src="../javaScript/checkbox/js/jquery-1.9.1.min.js"></script> |
| 11 | +<script> |
| 12 | + function showScore($ele, num, secand, pause){ //second 按照秒数,动画运行多少秒 |
| 13 | + if (!secand) { secand = 2;} |
| 14 | + if (!pause) { pause = 20;} |
| 15 | + |
| 16 | + var len = String(num).length; |
| 17 | + |
| 18 | + var temnum, times = 0 , stepTimes, max ; |
| 19 | + var numArr = String(num).split(""); |
| 20 | + |
| 21 | + |
| 22 | + function getRandom(n){ |
| 23 | + var num = Math.floor(Math.random()*(Math.pow(10, n)-1 - Math.pow(10, n-1))+Math.pow(10, n-1)); |
| 24 | + |
| 25 | + if (String(num).length !== n) {num = getRandom(n);} |
| 26 | + |
| 27 | + return num; |
| 28 | + } |
| 29 | + |
| 30 | + function setValue(num, pause, secand){//second 运行多少秒后停止 |
| 31 | + var len = String(num).length, j=0; |
| 32 | + |
| 33 | + if (!stepTimes) { |
| 34 | + max = Math.ceil(secand*1000/len); |
| 35 | + stepTimes = Math.ceil(max/pause); |
| 36 | + } |
| 37 | + |
| 38 | + temnum = ""; |
| 39 | + setTimeout(function(){ |
| 40 | + for (var i = 1; i <= len; i++) { |
| 41 | + if (times >= stepTimes*i) { |
| 42 | + j++; |
| 43 | + temnum += numArr[i-1]+""; |
| 44 | + }else{ |
| 45 | + break; |
| 46 | + } |
| 47 | + }; |
| 48 | + |
| 49 | + if (j < len) { |
| 50 | + $ele.html(temnum+""+getRandom(len-j)); |
| 51 | + }else{ |
| 52 | + $ele.html(temnum); |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + if (times >= max || j >= len) {return;}; |
| 57 | + |
| 58 | + setValue(num, pause, secand); |
| 59 | + times++; |
| 60 | + |
| 61 | + }, pause); |
| 62 | + |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + setValue(num, pause, secand); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + showScore($(".num"), 2344, 1.5, 10); |
| 71 | +</script> |
| 72 | +</html> |