Change motion
One duration and one curve for each kind of motion, plus named springs. Every component reads the same tokens, so one change moves them all.
How items work · step 3 of 3 · 7 min read
Prompt for your agent
Your agent reads /docs/motion.md: the same text as this page, as Markdown.
Every Gelatin UI component that moves reads the same motion tokens. So all motion in your app feels the same, and you can change it in one place.
How the motion tokens work
Each kind of motion has one duration token and one curve. A component never writes its own number. For example, every menu that opens uses --motion-popup. Change a token, and every component that uses it follows.
You add nothing. A component that moves adds the motion-timing item for you. That item writes these tokens.
Rules
- Move for a reason. Animate a change only when it moves content or must catch the eye. Content that should just be there has no motion.
- Keep it short. A UI motion ends in about 300ms. Only a theme change, a chart, or a loop takes longer.
- Do not animate frequent actions. Typing, a key press, and any action done many times a minute get instant feedback.
- Keep it interruptible. A new change starts from where the motion is now. It never waits for the old motion to end.
- Move
transformandopacityonly. A motion ofheight,width, ormarginmoves the page around it. So each one has a recorded reason. - Stay in the frame budget. A part moves 15px a frame or less. See Budget.
- Each component stands alone. A component loads only the Motion features it uses. So a component with a fade does not pay for drag or layout.
Durations
One token for each kind of motion. An exit is shorter than its enter, so a closed thing gets out of the way fast.
Loading delay
--motion-loading-delay is 300ms. A spinner or a skeleton waits this long before it shows. So a fast load shows no spinner at all. In a class, use delay-loading.
Curves
Five curves cover every tween (a motion with a fixed time and a curve).
Use the tokens in classes
Each duration is also a Tailwind class. duration-popup sets --motion-popup, and ease-popup sets its curve.
Change the speed
--motion-speed sets the speed of all motion. It is a multiplier, and 1 is the designed speed. It scales every token in Durations and the CSS spring durations. The loading delay does not change.
Springs
A spring has a time (visualDuration) and a bounce, not stiffness and damping. There are two roles:
- A spatial spring moves position, size, or rotation. It can overshoot.
- An effects spring moves opacity or color. It never bounces.
A time spring keeps its speed when its target changes during the motion. So a fast second change does not stop and start again.
- In Motion code, use
motionSpring("glide")from@/lib/motion. - In CSS, each spring is a
linear()curve with its own duration:ease-spring-glide duration-spring-glide.
Budget
A part moves at most 15px in one frame, at 60 frames a second. Above that, the eye sees a jump, not a move. The first frame moves about 10 to 15% of the distance.
Next steps
- Change the theme: change the colors, the radius, and the fonts.
- Compose items from parts: build with a root and named parts.