原语 / Animate UI
Blur · Animate UI
入场原语:在加载时或滚动进入视口时,把元素从模糊带到清晰。
安装
自有原语直接来自 @animate-ui/react,不依赖 Radix UI、Base UI 或 React Aria;装上包即可使用。
bun add @animate-ui/react motion用法
直接从 @animate-ui/react 的对应子路径引入,下面就是完整示例;样式由你的类名决定。
import { Blur, Blurs } from '@animate-ui/react/primitives/effects/blur';
export function Hero() {
return (
<>
<Blur>
<h1>Animated primitives for React</h1>
</Blur>
{/* Staggered: each child starts 100ms after the previous one. */}
<Blurs holdDelay={100}>
<Card />
<Card />
<Card />
</Blurs>
</>
);
}动效
- 元素从 initialBlur 收敛到 blur,弹簧 stiffness 200 / damping 20,从 10px 到清晰约 250ms。
- 可只在进入视口时播放一次;减少动效下直接呈现最终清晰度。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 见上表。
| 属性 | 类型 | 默认值 |
|---|---|---|
| asChild | boolean | false |
| initialBlur | number | 10 |
| blur | number | 0 |
| delay | number | 0 |
| transition | Transition | { type: 'spring', stiffness: 200, damping: 20 } |
| inView | boolean | false |
| inViewOnce | boolean | true |
| inViewMargin | string | '0px' |
| …props | HTMLMotionProps<'div'> | — |
| children | React.ReactElement | React.ReactElement[] | — |
| holdDelay | number | 0 |
| …props | BlurProps | — |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。