counter
// <div class="counter">0</div>
let from = 0;
const to = 4.9;
const time = 1000;
const substract = to - from;
const refresh = 20;
const counter = document.querySelector('.counter');
const loops = time / refresh;
const increment = substract / loops;
const delay = time / loops;
// const startTime = +new Date();
const interval = setInterval(() => {
from += increment;
counter.innerText = `${from.toFixed(2)}`;
if (from >= to) {
// console.log('Time:', +new Date() - startTime);
counter.innerText = `${to.toFixed(2)}`;
clearInterval(interval);
}
}, delay);
// https://codepen.io/anon/pen/ajVKpG