原语 / Animate UI
Particles · Animate UI
从元素一侧爆出的粒子,用于点赞、收藏与庆祝。
安装
自有原语直接来自 @animate-ui/react,不依赖 Radix UI、Base UI 或 React Aria;装上包即可使用。
bun add @animate-ui/react motion用法
直接从 @animate-ui/react 的对应子路径引入,下面就是完整示例;样式由你的类名决定。
import { Particles, ParticlesEffect } from '@animate-ui/react/primitives/effects/particles';
export function LikeButton({ liked }: { liked: boolean }) {
return (
<Particles animate={liked}>
<button>Like</button>
<ParticlesEffect className="size-1 rounded-full bg-red-500" />
</Particles>
);
}动效
- count 个粒子从元素一侧的一点射出,在 spread 角度内散开,然后缩小淡出,共 800ms ease-out。
- 粒子之间相隔 holdDelay 依次出发;减少动效下不播放。
所有时长都会乘以 AnimateUIProvider 的 tempo,并遵守系统的减少动效设置。
API
动效相关的 transition 与 exitTransition 是 Animate UI 唯一新增的属性;其余 props 见上表。
| 属性 | 类型 | 默认值 |
|---|---|---|
| asChild | boolean | false |
| animate | boolean | true |
| children | React.ReactNode | — |
| inView | boolean | false |
| inViewOnce | boolean | true |
| inViewMargin | string | '0px' |
| …props | HTMLMotionProps<'div'> | — |
| side | 'top' | 'bottom' | 'left' | 'right' | 'top' |
| sideOffset | number | 0 |
| align | 'start' | 'center' | 'end' | 'center' |
| alignOffset | number | 0 |
| count | number | 6 |
| radius | number | 30 |
| spread | number | 360 |
| duration | number | 0.8 |
| holdDelay | number | 0.05 |
| delay | number | 0 |
| transition | Transition | — |
| …props | HTMLMotionProps<'div'> | — |
未列出的属性与上游 API 完全一致,可在 官方文档 查阅。
内容对应官方文档 2026-10-18 版本。