js纯数字逐一停止显示效果的实现代码
内容摘要
js纯数字逐一停止显示效果的实现代码
function showScore($ele, num, secand, pause){ //second 按照秒数,动画运行多少秒
if (!secand) { secand = 2;}
i
function showScore($ele, num, secand, pause){ //second 按照秒数,动画运行多少秒
if (!secand) { secand = 2;}
i
文章正文
js纯数字逐一停止显示效果的实现代码
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 | 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); |
效果纯数字逐一停止显示效果,比如这个个数字不停的变化,第一位先定下来,第二位再确定,然后第三位再确定下来。因为项目用了几天废弃,所以存下档。
以上这篇js纯数字逐一停止显示效果的实现代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持phpstudy。
代码注释