原语 / Animate UI
Sliding Text · Animate UI
文字滑出框外、副本从另一侧滑入,像菜单链接的悬停效果。
安装
自有原语直接来自 @animate-ui/react,不依赖 Radix UI、Base UI 或 React Aria;装上包即可使用。
bun add @animate-ui/react motion用法
直接从 @animate-ui/react 的对应子路径引入,下面就是完整示例;样式由你的类名决定。
import { SlidingText } from '@animate-ui/react/primitives/texts/sliding';
export function NavLink() {
return (
<a href="/docs">
<SlidingText text="Docs" />
</a>
);
}动效
- 文字在裁剪框内沿自身高度加 0.6em 间距滑出,副本从另一侧滑入,0.25s ease-in-out。
- 可悬停触发或点击触发;减少动效下直接切换。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 见上表。
| 属性 | 类型 | 默认值 |
|---|---|---|
| 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'> | — |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。