WebberUI

Lightning

程序生成分支閃電並發光,以 canvas 2D 分形演算法即時繪製暴風雷電背景。

以「線段中點位移」分形演算法程序生成分支閃電,主通道帶白色核心與外層發光暈,週期性擊發並淡出,全程用 2D canvas 繪製、無任何外部相依。

載入預覽⋯

Playground

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

2200
6
0.35
<Lightning />

安裝

npx shadcn@latest add https://webberui.com/r/lightning.json

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

安裝依賴後,從 registry JSON(/r/lightning.jsonfiles[0].content)複製 lightning.tsx 原始碼到你的 components/ui/ 目錄:

npm install motion clsx tailwind-merge

使用

import { Lightning } from "@/components/ui/lightning";

<Lightning className="flex h-[320px] w-full items-center justify-center rounded-xl">
  <h3 className="text-4xl font-bold text-white">Electrify.</h3>
</Lightning>

容器需要自行給定高度(例如 h-[320px]),閃電會填滿整個容器並把 children 疊在其上。

Props

Prop型別預設值說明
colorstring"#7dd3fc"閃電主色
glowColorstringcolor發光暈色
intervalnumber2200平均擊發間隔(毫秒),實際在 0.6~1.4 倍間隨機
detailnumber6分形細分次數,越大鋸齒越細碎(建議 4~7
branchDensitynumber0.35分支生成機率 0~1,越大分岔越多
glowbooleantrue是否疊加發光暈
flashbooleantrue擊發瞬間是否讓整個容器閃一下
childrenReactNode疊在閃電之上的前景內容
classNamestring透傳到根容器,用來設定高度與佈局

可及性

  • 使用者系統開啟「減少動態效果」時,只繪製一道靜態閃電,不啟動動畫迴圈
  • Canvas 帶 aria-hiddenpointer-events-none,純裝飾、不干擾互動與輔助科技
  • 元件離開畫面時會 cancelAnimationFrame 並斷開 ResizeObserver,不留下背景運算

On this page