WebberUI

Tracing Beam

沿 SVG 路徑隨捲動前進的光束,適合長文、時間軸與逐步導覽。

一條沿左側軌道垂直延伸的漸層光束,端點跟著捲動進度前進,並用 spring 平滑;快速捲動時尾端會被速度拉出彗星般的拖影。把內容當 children 傳入即可,元件會自動量測高度決定路徑長度。

載入預覽⋯

Playground

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

40
500
90
<TracingBeam />

安裝

npx shadcn@latest add https://webberui.com/r/tracing-beam.json

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

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

npm install motion clsx tailwind-merge

使用

import { TracingBeam } from "@/components/ui/tracing-beam";

<TracingBeam>
  <article className="prose">{/* 你的長文內容 */}</article>
</TracingBeam>;

光束會依 children 的實際高度延伸。內容用會捲動的祖先容器包起來,捲動時光束就會前進。

Props

Prop型別預設值說明
childrenReact.ReactNode沿光束呈現的內容,高度由此量測
colors[string, string, string]["#18CCFC", "#6344F5", "#AE48FF"]光束漸層三色(由上而下)
gutternumber40內容與左側軌道的水平間距(px)
stiffnessnumber500追蹤捲動的 spring 剛性,越大越跟手
dampingnumber90追蹤捲動的 spring 阻尼,越大越穩定
classNamestring透傳到最外層容器

可及性

  • 使用者系統開啟「減少動態效果」時,光束靜態呈現完整漸層,不做脈動與捲動動畫
  • 光束軌道為純裝飾,標記 aria-hidden,不干擾螢幕閱讀器朗讀內容
  • 首次渲染與 SSR 一致,掛載後才量測高度並啟用捲動追蹤,避免 hydration 落差

On this page