卡片與網格

Pixel Reveal Card

以像素溶解揭示內容的卡片

覆蓋在卡片內容上的彩色像素會依指定順序逐格淡出,像馬賽克被風吹散一樣揭示底下的內容。支援懸停與進入視口兩種觸發方式,整個效果以 2D canvas 繪製,效能穩定。

把這個效果裝進你的專案

在專案資料夾執行指令,CLI 會加入原始碼與依賴套件,再依下方使用範例引用元件。

npx webberui@latest add pixel-reveal-card

還沒有專案,或安裝遇到問題?看快速開始 →

Playground

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

16
0.9
編輯中的呼叫預設屬性
<PixelRevealCard/>

完整範例包含預覽的排版與資料。先安裝元件,再把範例檔貼入你的專案。

安裝

npx webberui@latest add https://webberui.com/r/pixel-reveal-card.json

或在 components.json 設定 registries 後,改用 @webberui/pixel-reveal-card 安裝。

使用

import { PixelRevealCard } from "@/components/ui/pixel-reveal-card";

<PixelRevealCard trigger="hover" pixelSize={14} className="h-[300px] w-[260px]">
  <div className="flex h-full w-full flex-col justify-end bg-gradient-to-br from-indigo-500 to-fuchsia-500 p-5 text-white">
    <h3 className="text-xl font-semibold">Nebula Pass</h3>
    <p className="mt-1 text-sm text-white/80">Hover to reveal.</p>
  </div>
</PixelRevealCard>

卡片內容照常寫在 children,覆蓋期間內容仍在 DOM 中,可被輔助科技讀取。容器預設沒有高度,請透過 className 給定明確尺寸(例如 h-[300px] w-[260px])。

Props

Prop型別預設值說明
childrenReact.ReactNode—要被揭示的卡片內容
trigger"hover" | "view""hover"觸發方式:懸停切換或進入視口自動揭示
pixelSizenumber16單一像素邊長(px),越小顆粒越細
colorsstring[]靛紫洋紅四色覆蓋層配色,逐格隨機取用形成馬賽克
direction"random" | "left" | "right" | "top" | "bottom" | "diagonal""random"像素溶解的排序方向
durationnumber0.9完整溶解或回填所需時間(秒)
oncebooleantruetrigger="view" 時是否只揭示一次
classNamestring—透傳到最外層容器,用來給定尺寸與樣式

可及性

  • 使用者系統開啟「減少動態效果」時,直接顯示內容、不繪製像素覆蓋層
  • 覆蓋期間內容仍在 DOM,canvas 覆蓋層標記 aria-hidden,不影響輔助科技朗讀
  • hover 模式的卡片可被鍵盤聚焦(focus 即揭示、blur 即回填)