JSFiddle - React, Tailwind, and code Playground
by TekVanDo
HTML
<div id="example"></div>
<div id="test"></div>
JavaScript
function number_to(id, from, to, duration) {
var element = document.getElementById(id);
var start = new Date().getTime();
setTimeout(function () {
var now = (new Date().getTime()) - start;
var progress = now / duration;
var result = Math.floor((to - from) * progress + from);
element.innerHTML = progress < 1 ? result : to;
if (progress < 1) setTimeout(arguments.callee, 10);
}, 10);
}
number_to("example", 900, 1500, 3000);
number_to("test", 10, -5, 15000)