媒體

Hero Video Dialog

點擊播放的 hero 影片彈窗,帶縮圖、播放鍵脈衝與多種進出動畫。

點擊縮圖即以彈窗播放影片,支援多種進出動畫、背景模糊、Escape 與點擊背景關閉,並鎖住背景捲動。

把這個效果裝進你的專案

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

npx webberui@latest add hero-video-dialog

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

Playground

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

編輯中的呼叫預設屬性
<HeroVideoDialog/>

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

安裝

npx webberui@latest add https://webberui.com/r/hero-video-dialog.json

或在 components.json 設定 registries 後,改用 @webberui/hero-video-dialog 安裝。

使用

videoSrc 預設以 iframe 內嵌,適用 YouTube、Vimeo 等嵌入網址;thumbnailSrc 由你自行提供。

import { HeroVideoDialog } from "@/components/ui/hero-video-dialog";

<HeroVideoDialog
  videoSrc="https://www.youtube.com/embed/VIDEO_ID"
  thumbnailSrc="/thumbnail.jpg"
  thumbnailAlt="Product overview"
  animationStyle="from-center"
/>;

若要放入自家播放器或完全自足的內容,改用 children 取代預設 iframe:

<HeroVideoDialog thumbnailSrc="/thumbnail.jpg">
  <video src="/demo.mp4" controls autoPlay className="h-full w-full" />
</HeroVideoDialog>;

動畫風格

animationStyle 可選:from-center、from-bottom、from-top、from-left、from-right、fade、top-in-bottom-out、left-in-right-out。

Props

Prop型別預設值說明
videoSrcstring—影片網址,預設以 iframe 內嵌
thumbnailSrcstring—縮圖網址;未提供時顯示內建漸層佔位
thumbnailAltstring"Video thumbnail"縮圖替代文字,同時作為彈窗標籤
animationStyleHeroVideoAnimationStyle"from-center"彈窗進出動畫風格
playButtonLabelstring"Play video"播放鍵的無障礙標籤
childrenReactNode—自訂彈窗內容,提供時取代預設 iframe
classNamestring—透傳到縮圖外框的樣式

可及性

  • 縮圖為 button,帶 aria-label 與可見的鍵盤 focus ring
  • 彈窗為 role="dialog" 且 aria-modal,支援 Escape 與點擊背景關閉
  • 開啟時鎖住背景捲動,關閉後還原
  • 使用者開啟「減少動態效果」時,僅以淡入淡出呈現,播放鍵脈衝停用