Text that slides out of its box while a copy slides in, on hover or on click, like a menu link.
Sliding Text
Installation
Usage
import { SlidingText } from '@animate-ui/react/primitives/texts/sliding';
export function NavLink() {
return (
<a href="/docs">
<SlidingText text="Docs" />
</a>
);
}Animation
- The text sits in a box that clips it. On
hover, it slides out by its own height plus a small gap (0.6em) while a copy of it slides in from the other side, in 0.25s on an ease-in-out. direction="down"sends the text down and brings the copy from above;direction="up"does the opposite.- With
trigger="hover", leaving slides it back the other way. Left halfway, it turns back from where it is. - With
trigger="click", each click slides it once more in the same direction. A click during a slide carries it on without a jump. - The box keeps the text's size and baseline, so it fits inside a line, a link or a button. A text on several lines slides as a whole.
<AnimateUIProvider tempo>paces the default transition.- Under reduced motion, the text doesn't move.
- Screen readers read the text once: the copy is hidden from them.
API Reference
SlidingText
| Prop | Type | Default |
|---|---|---|
text | string | - |
direction? | 'down' | 'up' | 'down' |
trigger? | 'hover' | 'click' | 'hover' |
transition? | Transition | { duration: 0.25, ease: [0.4, 0, 0.2, 1] } |
...props? | Omit<HTMLMotionProps<'span'>, 'children'> | - |