没有录屏软件,就不录制了,反正肯定没问题,效果杠杠的
调用示例:
let options={ time: 3000,num: 12000,regulator: 20}
NumAutoPlusAnimation("dataid",options)
function代码
// byh 数字自增到某一值动画参数 、
// targetEle 目标元素(需要动画的id属性值)
// options={ time: 1500,num: 12000,regulator: 20}
function NumAutoPlusAnimation(targetEle, options) {
options = options || {};
var $this = document.getElementById(targetEle),
time = options.time || 1500, //总时间--毫秒为单位
finalNum = options.num || 0, //要显示的真实数值
regulator = options.regulator || 100, //调速器
step = finalNum / (time / regulator),/*每30ms增加的数值--*/
count = 0, //计数器
initial = 0;
var timer = setInterval(function () {
count = count + step;
if (count >= finalNum) {
clearInterval(timer);
count = finalNum;
}
var t = Math.floor(count);
if (t === initial) return;
initial = t;
$this.innerHTML = initial;
}, 30);
}