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.
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.
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.
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.
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.
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.