No.35 · Buttons
Magnetic Button
A button with a pull: as the pointer comes near the pill leans toward it, the label leans further, and on leaving it springs back with a little overshoot.
The prompt
The design brief behind this component — reuse it to regenerate, remix, or explain it.
Build a pill button (56px; solid colours from --bg and --fg, plus a ghost style with a hairline ring) that is magnetic. A window pointermove listener measures the pointer's offset from the button's centre; within a reach of 140px plus half the button's size, the target offset is that vector × 0.32 × (1 − d/reach)^0.6, so the pull is strongest close in and fades smoothly. The pill's translate follows the target on a spring (velocity += (target − x)·0.16, ×0.74 damping per frame), so letting go springs back with a small overshoot; the label translates a further 40% of the same offset for parallax. A soft white radial light (120px) sits under the pointer inside the pill and its strength and the drop shadow's depth grow with the pull. Press scales to 0.96. The loop runs only while the spring is moving, and the effect is off on touch and under reduced motion.
Notes
- Interaction
- Bring the pointer near and the button leans toward it; press to click.
- Motion
- Spring stiffness 0.16, damping 0.74; press 180ms.
- Accessibility
- A normal button; the magnetism is pointer-only and removed under reduced motion and on touch, so keyboard and touch use is unaffected.
- Responsive
- Sized by its label; works at any width.
- On touch
- Taps work normally; pointer-only effects are skipped on touch.