Skip to content
← All articles

Noa Lindqvist /animation 5 min

Damped springs instead of per-frame tweens

Why calling a tween library every frame makes a 3D slider feel rubbery, and the one-line function that fixes it.

  • #animation
  • #javascript

A slider that starts a new tween for every card on every frame is fighting itself: each tween is overwritten before it gets anywhere, on top of a lerp that is already smoothing the input.

Frame-rate independent damping

const damp = (a, b, lambda, dt) => a + (b - a) * (1 - Math.exp(-lambda * dt));

Every frame, compute where each card should be and move it a fraction of the way. The result is identical at 60 and 120 Hz, interrupts gracefully and costs nothing.

Continuous layouts

Use smoothstep between the centre and the neighbours instead of if (offset > 0) branches, and the card no longer jumps when it crosses the middle.