Rotating Text
A component that animates between multiple text strings with smooth transitions.
The Rotating Text component creates smooth, animated transitions between different text strings. It's perfect for highlighting multiple features, benefits, or descriptive words in a limited space.
Preview
Usage
The Rotating Text component can be used to create engaging text animations that cycle through different words or phrases. It supports various animation styles and can be customized to match your design.
Features
- Smooth Animations: Creates fluid transitions between different text strings.
- Character-Level Animation: Animates each character individually for a more engaging effect.
- Customizable Timing: Control the rotation interval and animation duration.
- Multiple Animation Styles: Choose from different animation styles (slide up, fade, slide side).
- Staggered Animations: Characters animate with a staggered delay for a more natural effect.
- Flexible Configuration: Extensive props for customizing the appearance and behavior.
- AnimeJS Integration: Powered by AnimeJS for smooth, high-performance animations.
Component Code
The component uses AnimeJS for smooth animations. You can view and copy all the necessary files below.
Props
Prop | Type | Default | Description |
---|---|---|---|
texts | string[] | Required | Array of text strings to rotate through |
transition | object | { type: "spring", damping: 25, stiffness: 300, duration: 0.4 } | Animation transition properties |
initial | object | { y: "100%", opacity: 0 } | Initial state of entering text |
animate | object | { y: 0, opacity: 1 } | Animated state of visible text |
exit | object | { y: "-120%", opacity: 0 } | Exit state of leaving text |
rotationInterval | number | 2000 | Time in ms between text rotations |
staggerDuration | number | 0.025 | Delay between each character's animation |
staggerFrom | "first" | "last" | "center" | "random" | number | "first" | Where the stagger animation starts from |
loop | boolean | true | Whether to loop through texts continuously |
auto | boolean | true | Whether to auto-rotate through texts |
splitBy | string | "characters" | How to split text ("characters", "words", "lines") |
mainClassName | string | "" | Class for the main container |
splitLevelClassName | string | "" | Class for the split level elements |
elementLevelClassName | string | "" | Class for the individual character elements |
Methods
The component exposes the following methods that can be called using a ref:
Method | Parameters | Description |
---|---|---|
next() | None | Advance to the next text |
previous() | None | Go back to the previous text |
jumpTo() | index: number | Jump to a specific text by index |
reset() | None | Reset to the first text |
Example
Credits
- Credits to Unite-ui Team for this component.