WebberUI

Aurora Background

極光流動背景:大型模糊色塊以 transform 緩慢漂移,可選噪點疊層與滑鼠跟隨。

載入預覽⋯

Playground

即時調整 props、程式碼片段同步更新——直接試出你要的樣子再複製。

<AuroraBackground />

安裝

npx shadcn@latest add https://webberui.com/r/aurora-background.json

或在 components.json 設定 registries 後,改用 @webberui/aurora-background 安裝。

安裝依賴後,打開 aurora-background.json,把 files[0].content 的內容複製到你的 components/ui/aurora-background.tsx

npm install motion clsx tailwind-merge

使用

前景內容直接放進 children,佈局(如置中、高度)寫在 className 上:

import { AuroraBackground } from "@/components/ui/aurora-background";

<AuroraBackground className="flex min-h-[400px] items-center justify-center">
  <h1 className="text-4xl font-bold">Hero 標題</h1>
</AuroraBackground>

自訂配色、開啟噪點與滑鼠跟隨:

<AuroraBackground
  colors={["#f472b6", "#a78bfa", "#38bdf8"]}
  grain
  interactive
  className="flex h-[320px] items-center justify-center rounded-2xl"
>
  <p className="text-lg">暖色系極光</p>
</AuroraBackground>

Props

Prop型別預設值說明
colorsstring[]冷色系極光配色三個極光漸層色,依序對應三個色塊
interactivebooleanfalse色塊輕微跟隨滑鼠(僅滑鼠指標生效,觸控不作用)
grainbooleanfalse疊加低透明度噪點,減少大面積漸層的色帶感
childrenReact.ReactNode前景內容,疊在極光之上
classNamestring附加到最外層容器的 class

細節

  • 效能:只動 transform。 三個色塊的漂移全部走 x / y / scale,不觸碰 top / left,不觸發 layout 與 paint;will-change 由 Motion 在動畫期間自動管理,毋須手動設定
  • 每個色塊各自不同週期(17s / 23s / 19s)搭配 repeat: Infinity + repeatType: "mirror",在原點與目標間往返,三塊永不同步,看起來像自然流動
  • 色塊是 blur-3xlradial-gradient 圓形,模糊由 GPU 合成一次後隨 transform 平移,成本固定,不隨動畫累加
  • 背景層整層 pointer-events-none 並以 -z-10 沉到內容之下(容器有 isolate 建立獨立堆疊上下文),前景互動完全不受影響
  • interactive 開啟時,游標位置正規化為 -1 ~ 1,經低剛性 useSpring 平滑後,各色塊乘上不同的 depth 幅度(含正負值),形成輕微視差;只在 pointerType === "mouse" 時作用
  • 噪點是內嵌 feTurbulence SVG 的 data URI,無額外網路請求,以 180px 平鋪、低透明度疊在色塊之上
  • 使用者系統開啟「減少動態效果」時,漂移與滑鼠跟隨全部停用,色塊以靜態漸層渲染,DOM 結構不變

On this page