原语 / Animate UI
Rotating Text · Animate UI
同一个位置上轮流出现的词组,前一个滑出、后一个滑入。
安装
自有原语直接来自 @animate-ui/react,不依赖 Radix UI、Base UI 或 React Aria;装上包即可使用。
bun add @animate-ui/react motion用法
直接从 @animate-ui/react 的对应子路径引入,下面就是完整示例;样式由你的类名决定。
import {
RotatingText,
RotatingTextContainer,
} from '@animate-ui/react/primitives/texts/rotating';
export function Tagline() {
return (
<RotatingTextContainer text={['Fast', 'Accessible', 'Animated']}>
<RotatingText />
</RotatingTextContainer>
);
}动效
- 当前词按 y 方向滑出并淡出,下一个从另一侧滑入,各 0.3s ease-out,依次衔接。
- 之后每隔 duration 切换一次;无 delay 时第一个词直接离场;减少动效下直接替换。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 见上表。
| 属性 | 类型 | 默认值 |
|---|---|---|
| text | string | string[] | — |
| duration | number | 2000 |
| y | number | -50 |
| delay | number | 0 |
| align | 'start' | 'center' | 'end' | — |
| inView | boolean | false |
| inViewMargin | string | '0px' |
| inViewOnce | boolean | true |
| …props | React.ComponentProps<'div'> | — |
| transition | Transition | { duration: 0.3, ease: 'easeOut' } |
| …props | Omit<HTMLMotionProps<'div'>, 'children'> | — |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。