WebberUI

Moving Border Button

邊框繞行發光的凸顯按鈕,一顆彗星般的光點沿圓角邊框巡遊。

一顆柔光光點沿著圓角邊框巡遊,替按鈕鑲上不斷流動的發光邊框,適合用在最想被點擊的主要行動呼籲。

載入預覽⋯

Playground

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

16
4
130
<MovingBorderButton />

安裝

npx shadcn@latest add https://webberui.com/r/moving-border-button.json

或在 components.json 設定 registries 後,改用 @webberui/moving-border-button 安裝。

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

npm install motion clsx tailwind-merge lucide-react

使用

import { MovingBorderButton } from "@/components/ui/moving-border-button";

<MovingBorderButton onClick={() => console.log("clicked")}>
  Get Started
</MovingBorderButton>

圓角膠囊、雙光點、自訂顏色:

<MovingBorderButton
  dual
  borderRadius={9999}
  colorFrom="#f472b6"
  colorTo="#a855f7"
>
  Upgrade to Pro
</MovingBorderButton>

Props

除下表外,其餘原生 <button> 屬性(onClickdisabledtype 等)皆會透傳。

Prop型別預設值說明
borderRadiusnumber16圓角半徑(px);光點沿此圓角矩形巡遊
durationnumber4光點繞行一圈的時長(秒),越小越快
borderWidthnumber1邊框環寬度(px),外層與內襯之間露出的縫隙
glowSizenumber130光點直徑(px),越大拖尾越長
colorFromstring"#22d3ee"光點核心色(漸層起點)
colorTostring"#818cf8"光點外緣色(漸層中段,之後淡出)
reversebooleanfalse逆時針巡遊
dualbooleanfalse在對側再放一顆光點,形成雙彗星對稱環繞
classNamestring內襯(按鈕面)的樣式
containerClassNamestring外層容器(尺寸、外距)的樣式

可及性

  • 使用者系統開啟「減少動態效果」時,光點停止巡遊,改以固定漸層環呈現邊框
  • 元件即原生 <button>,鍵盤聚焦與 disabled 狀態皆保留,聚焦時顯示 focus ring

On this page