motion-swap
Splits text into individual characters and swaps them vertically on hover or scroll reveal. Each character has an original and duplicate that trade places with a spring animation.
Preview
Import
import 'motion-components/motion-swap' // just this one
import 'motion-components' // or the whole libraryUsage
<motion-swap>Hover me</motion-swap>Loop
Add loop to swap the word in, hold, swap it back out and swap in again. hold sets how
long the swapped word stays, gap how long it stays swapped back.
<motion-swap trigger="view" loop hold="1.4" gap="0.5">swap me</motion-swap>
The cycle runs only while the text is on screen, and once is ignored. Add
pause-on-hover to freeze it while the pointer is over the text.
Properties
| Attribute | Property | Type | Default | Description |
|---|---|---|---|---|
| | | string | 'hover' | Animation trigger: |
| | | boolean | true | Letters swap bottom-to-top. Set |
| | | number | 0.03 | Delay in seconds between each character's animation start |
| | | number | 0.7 | Spring duration of each character swap, in seconds |
| | | number | 0.3 | Spring bounciness: |
| | | boolean | true | Animate only on first intersection ( |
| | | number | 0 | Delay in seconds before animation starts |
| | | boolean | false | Swap in, hold, swap out and swap in again on repeat. With |
| | | number | 1.6 | With |
| | | number | 0.5 | With |
| | | boolean | false | Pause the loop while the pointer is over the text, resuming on leave |
JavaScript API
Control the swap view mode programmatically with play() and cancel().
Accessibility
Respects prefers-reduced-motion: when enabled, the swap effect is skipped, the text appears at its default state and loop never starts.