js加载从0到80变化过程代码,让其4s中加载完毕
function textAnimation(start, end, sec){ var val = start; var delay = sec * 1000 / Math.abs(end - start); if(delay < 1000 / 60){ delay = 1000 / 60; } var step = (end - start) / (sec * 1000 / delay); var interval = setInterval(function () { if (val < end) { // el.innerText = val; self.setState({ progressPer: val }) val += step; val = Math.floor(val); }else{ console.log('ended'); // el.innerText = end; self.setState({ progressPer: end }) clearInterval(interval); } }, delay); } textAnimation(0, 100, 4);
作者:wj704
出处:http://www.cnblogs.com/wj204/