HTML DOM 影片結束屬性


HTML DOM Video 結束屬性返回一個布林值(真/假),表示影片是否播放完畢。

語法

語法如下 −

返回布林值

mediaObject.ended

我們來看一個 HTML DOM Video ended 屬性的示例 −

示例

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video ended</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Video-ended</legend>
         <video id="demo" width="320" controls><source    src="https://tutorialspoint.tw/html5/foo.mp4" type="video/mp4"></video><br>
         <input type="button" onclick="getTrackDetails()" value="How many seconds before the video ends?">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var demo = document.getElementById("demo");
   function getTrackDetails() {
      if(demo.ended === false)
         divDisplay.textContent = 'Video ends in: '+(demo.duration - demo.currentTime)+' seconds';
   }
</script>
</body>
</html>

輸出

點選 ‘影片結束前還有多少秒?’ 按鈕之前 −

點選 ‘影片結束前還有多少秒?’ 按鈕之後 −

更新日期: 2021 年 12 月 21 日

103 次瀏覽

啟動您的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.