背景
Hexagon 背景
铺满容器的六边形网格,悬停的格子会立即点亮,离开后用 1s 淡出并留下拖尾。
安装
背景是项目里的一个文件,用 shadcn CLI 添加,然后按需要改颜色与速度。
bunx shadcn@latest add @animate-ui/backgrounds-hexagon用法
把背景放进一个定位容器,内容渲染在上层;容器需要自己处理溢出。
import { HexagonBackground } from '@/components/animate-ui/backgrounds/hexagon';
export function Hero() {
return (
<section className="relative h-[480px] overflow-hidden">
<HexagonBackground className="absolute inset-0" />
</section>
);
}动效
- 网格随容器尺寸变化重新计算格子数量,始终铺满且不变形。
- 悬停立即点亮,离开后 1s 淡出;只在支持 hover 的设备启用,触屏点击不会留下常亮格子。
所有背景都会在离开视口与标签页隐藏时暂停;减少动效时保留静止构图,不播放位移与循环。
API
| 属性 | 类型 | 默认值 |
|---|---|---|
| hexagonSize | number | 75 |
| hexagonMargin | number | 3 |
| hexagonProps | React.ComponentProps<'div'> | — |
| …props | React.ComponentProps<'div'> | — |
背景接受容器 div 的全部属性,className 用来控制位置与尺寸;内容作为children 渲染在背景之上。
内容对应官方文档 2026-10-18 版本。