如何在網頁背景中播放音檔?


HTML <audio> 元素用於在網頁中新增音訊。若要在網頁的背景中播放音檔,請使用 <embed>…</embed> 元素。此外,請使用 autoplay 屬性。這樣,不論何時載入網頁,音樂都會在背景中播放。

設定寬度和高度,使播放器在網頁上隱藏起來。loop 屬性用於指定音訊是否會再重新開始。

你可以嘗試執行以下程式碼,在網頁的背景中播放音檔

範例

即時範例

<!DOCTYPE html>
<html>
   <head>
      <title>HTML background music</title>
   </head>
   <body>
      <p>The music is running in the background.</p>
      <p>(Song: Kalimba which is provided as a Sample Music in Windows)</p>
      <embed src="/html/Kalimba.mp3" loop="true" autostart="true" width="2"
         height="0">
   </body>
</html>

更新於:2020 年 2 月 25 日

2.4 萬次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.