INNER CODE UNIT · JavaScript
roll
LeyckerS/moondownloader · web/app.js:201
function roll(el, to, fmt) {
const from = Number(el.dataset.v || 0);
if (!isFinite(to)) return;
if (Math.abs(to - from) < 1e-4) { el.textContent = fmt(to); return; }
cancelAnimationFrame(el._raf);
const t0 = performance.now();
const dur = 340;
const tick = (now) => {
const k = Math.min(1, (now - t0) / dur);
const eased = 1 - Math.pow(1 - k, 3);
el.textContent = fmt(from + (to - from) * eased);
if (k < 1) el._raf = requestAnimationFrame(tick);
else { el.dataset.v = String(to); el.textContent = fmt(to); }
};
el.dataset.v = String(to);
el._raf = requestAnimationFrame(tick);
}