Journal
Sep 21, 2026·2 min read· Engineering

Animate by time, not by frame

I shipped a loading bar that crawled on one machine and raced on another. The code looked innocent:

shown += (target - shown) * 0.1;

Ten percent of the remaining distance, every frame. On a 60 Hz screen that runs 60 times a second. On a 120 Hz screen, 120 times. On a phone that is struggling, maybe 20. Same code, three different animations.

Use the clock

Measure how long the last frame took and scale by it:

const dt = (now - last) / 1000;
shown += (target - shown) * (1 - Math.exp(-dt * 6));

The exponential form matters. A plain speed * dt works for constant motion, but for "move a fraction of the way there" the correct frame-rate-independent version is the exponential one. The number 6 is how quickly it catches up; pick it by eye.

Clamp the step

After a tab has been in the background, the first frame can report a dt of several seconds and everything teleports. Cap it:

const dt = Math.min(0.1, (now - last) / 1000);

The same rule in three.js

useFrame in React Three Fiber hands you delta for this reason, and THREE.MathUtils.damp is the exponential form ready-made. If you write lerp(a, b, 0.1) inside a frame loop, you have written a frame-rate-dependent animation.

How to catch it

Test on a high-refresh display if you have one, and throttle the CPU in dev tools. If the feel changes, something is counting frames.