如何在你的網頁中新增背景音樂?


要在網頁上新增背景音樂,可以使用 <embed>…</embed> 元素。同時使用 autoplay 屬性。這樣就可以讓音樂在頁面載入時在背景中播放。

以一種在網頁上隱藏播放器的方式設定寬度高度loop 屬性被用來指定音訊是否會重新開始。將音樂檔案新增到伺服器,並在src 屬性中提及連結。

示例

你可以嘗試執行以下程式碼,在你的網頁中新增背景音樂

即時演示

<!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>

更新時間: 13-9月-2023

34K+ 訪問量

啟動您的 職業生涯

完成課程獲取認證。

開始
廣告
© . All rights reserved.