// Created on savesnippets.com ยท https://savesnippets.com/Wqb5g9Zc8dmtAI function animateCounter(element, from, to, duration = 1000, easing = (t) => t * (2 - t)) { const start = performance.now(); function update(now) { const t = Math.min((now - start) / duration, 1); element.textContent = Math.round(from + (to - from) * easing(t)).toLocaleString(); if (t < 1) requestAnimationFrame(update); } requestAnimationFrame(update); } // Usage const el = document.querySelector('#counter'); animateCounter(el, 0, 1_234_567, 2000);