如何在 HTML 5 中給網站背景新增影片?


新增一個按鈕來播放或暫停影片。然後,我們將影片的樣式設定為 100% 的高度和寬度,使其覆蓋整個背景。

以下是在 HTML5 中將影片設定為網站背景的程式碼段。

<video autoplay muted loop id = "myVideo">
   <source src = "demo.mp4" type = "video/mp4">
   Your browser does not support HTML5 video.
</video>

以下是暫停影片的程式碼 −

function display() {
   if (video.paused) {
      video.play();
      btn.innerHTML = "Pause the video!";
   } else {
      video.pause();
      btn.innerHTML = "Play";
   }
}

更新於: 2020 年 6 月 24 日

380 次瀏覽

開啟您的 職業生涯

完成課程認證

立即開始
廣告
© . All rights reserved.