StealThis .dev

Spring Physics Drag

Draggable cards powered by a real damped-spring integrator running in requestAnimationFrame. Fling a card and watch it coast on inertia, rubber-band past its bounds with elastic resistance, then settle back onto the grid with critically tuned overshoot. Live stiffness and damping sliders let you feel the difference between a stiff snap and a loose wobble, and everything degrades to an instant, motion-safe placement when the visitor prefers reduced motion.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

Spring Physics Drag is a small board of cards you can grab, throw, and let go. Instead of the usual CSS transition on release, each card is driven by a per-frame numeric integrator: pointer velocity is sampled during the drag, and on release that velocity seeds a critically-damped spring that pulls the card back to its home slot. The result feels physical — the card carries momentum, overshoots slightly, and settles with a natural decay rather than a canned easing curve.

While you drag past the edges of the board, the card meets an over-drag resistance that scales the excess offset logarithmically, giving the familiar iOS-style rubber-band pull. Two sliders expose the spring’s stiffness and damping constants so you can dial anything from a snappy, near-instant snap to a loose, wobbly bounce and watch the settle time and overshoot change in real time. A velocity readout and a live “energy” meter show when the integrator considers the card at rest.

The technique on show is a semi-implicit Euler spring solver — the same math behind React Spring, Framer Motion, and iOS UIView spring animations — implemented in about forty lines of vanilla JavaScript with no dependencies. It is DPR-agnostic, pointer-events based (mouse, touch, and pen all work), fully keyboard nudge-able, and it honours prefers-reduced-motion by skipping the animation loop and placing cards instantly.