Skip to content

Springs

A tween asks "how long should this take?". A spring asks "how heavy is this, and how hard is it pulled?" - and the duration falls out of the answer. That is why springs survive interruption: retarget one mid-flight and it carries its current velocity into the new motion instead of restarting. Bm.Spring(...) is the whole API, and it accepts either set of knobs below.

Stiffness and damping

Stiffness is how hard the spring pulls toward the target - raise it and the motion gets faster and more urgent. Damping is the friction that removes energy - lower it and the element overshoots and wobbles, raise it far enough and it eases in without ever crossing the target. Mass (default 1) scales the inertia behind both.

stiffness 400 · damping 40
fast, no overshoot
stiffness 100 · damping 10
the default feel
stiffness 50 · damping 5
loose and wobbly
stiffness 300 · damping 70
overdamped - it crawls in

Bounce and duration

Stiffness and damping are the physics, but they are not how anyone describes motion out loud. The second form takes the two words you would actually use: bounce (0 = no overshoot at all, 1 = very springy) and duration in visual seconds. Bmotion solves for the constants that produce it, so the same feel is reachable without tuning numbers by trial.

bounce 0 · duration 0.6
bounce 0.3 · duration 0.6
bounce 0.6 · duration 0.6
bounce 0.6 · duration 1.2

Named springs, measured

BmotionSprings names the springs interfaces reach for - Smooth for chrome, Snappy for clicks, Bouncy for lively entrances, Gentle for large surfaces, Stiff for small state changes, Heavy for things with weight and Responsive for following input. spring.Analyze() runs the engine's own spring driver on a virtual clock and reports what it does on screen: when it comes to rest, how far it overshoots, its damping ratio and a 60 Hz trace (drawn under each box). Use it to choose between springs on evidence, or to time something else to one.

BmotionSprings.Smooth()
rests 0.85s · no overshoot · ζ 1.00
BmotionSprings.Snappy()
rests 0.32s · no overshoot · ζ 0.78
BmotionSprings.Bouncy()
rests 0.83s · 11 % past · ζ 0.54
BmotionSprings.Gentle()
rests 0.93s · no overshoot · ζ 0.89
BmotionSprings.Stiff()
rests 0.43s · no overshoot · ζ 1.00
BmotionSprings.Heavy()
rests 1.45s · no overshoot · ζ 1.00
BmotionSprings.Responsive()
rests 0.35s · no overshoot · ζ 1.00

Mass and a starting push

mass is the inertia the spring has to move. With the stiffness and damping held, a heavier element is slower to get going and swings further past the target before the same friction stops it. velocity is a push the element already has when the spring takes over, in units per second - a negative one sends it the wrong way first, which is how a recoil or a flick reads. Left at 0, a spring that interrupts another animation inherits that animation's velocity instead (see below). Two more knobs, set on a new BmotionSpring { … }, decide when a spring counts as finished: RestSpeed and RestDelta, the speed and the distance from the target below which it stops. Raise them to cut a long, barely visible tail short.

mass 1
the default
mass 4
slower, swings further
velocity: -600
pushed the wrong way first

Interrupting mid-flight

Change the target while the element is still on its way, and the two kinds of transition part company. A tween starts its new run from where the element is, but it has no notion of speed: an InOut curve eases in from a standstill, so the turnaround is a visible stop. A spring carries the velocity it has into the new motion and curves round without one. Press the button, then press it again before the boxes arrive, and watch each one turn around.

Bm.Tween(0.9, BmotionEase.InOut) · stops, then turns
Bm.Spring(bounce: 0.15, duration: 0.9) · curves round

Overshoot on mount

An underdamped spring on an entrance is the cheapest way to make an interface feel alive: the element passes its resting state, comes back, and settles. Re-mount below to replay it - the @key change is what makes Blazor treat it as a new element, which is what makes Initial run again.

Repeating springs

BmotionRepeat replays a spring without an int.MaxValue sentinel anywhere in sight. Mirror ping-pongs back through the motion it just played; Loop jumps home and replays from the origin, optionally with a pause between runs. The count is the number of runs after the first, so BmotionRepeat.Loop(3) plays four times in all. The Keyframes page puts all three repeat types side by side.

Mirror · forever
Loop(3) · 3 more runs, 300 ms apart
Bmotion 0 el · 0 active ▸
An unhandled error has occurred. Reload 🗙