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);