纯数字逐一停止显示效果
2016-03-16 14:51
495 查看
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);
![](http://images2015.cnblogs.com/blog/570524/201603/570524-20160316144729474-123451035.jpg)
效果纯数字逐一停止显示效果,比如这个个数字不停的变化,第一位先定下来,第二位再确定,然后第三位再确定下来。因为项目用了几天废弃,所以存下档。
相关文章推荐
- 数据结构与算法学习笔记(五)
- SSRS 报表 递归列表
- 2、工厂方法模式
- 如何引入一个Schema 文件
- jquery tab
- sublime中配置Java 环境
- ngrep undefined symbol: pcap_restart 错误处理
- 310. Minimum Height Trees LeetCode
- 网络管理-NTP的配置
- la 4945 free goodies,不会!
- 高性能网站架构的思考
- PAT (Advanced Level) Practise 1054 The Dominant Color (20)
- 详解印染产品纬斜疵病产生原因及如何预防
- SQL统计查询(按月份)
- 工具类-px与dp互转
- jquery datagird 单元格悬停显示内容
- React中state和props的区别
- unity文本自发光效果
- 面试时,如何巧妙回答跳槽问题
- 浅谈CSRF攻击方式