HTML DOM 影片 width 屬性


HTML DOM Video width 屬性返回/設定與媒體寬度(以畫素為單位)相對應的數字。

語法

以下是語法 −

返回以數字(px)表示的寬度

mediaObject.width

將寬度設定為數字(px)

mediaObject.width = number

讓我們來看一個Video width 屬性的示例 −

示例

 現場演示

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video width</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-width</legend>
         <video id="demo" height="200" width="170" controls><source
         src="https://tutorialspoint.tw/html5/foo.mp4" type="video/mp4"></video><br>
         <input type="button" onclick="getTrackDetails()" value="Video Not Visible">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var demo = document.getElementById("demo");
      function getTrackDetails() {
         demo.width += 50;
         divDisplay.textContent = 'Video width: '+demo.width;
      }
   </script>
</body>
</html>

輸出

單擊“影片不可見”按鈕之前 −

單擊“影片不可見”按鈕 3 次 −

更新於:15-Feb-2021

88 次瀏覽

開啟你的 職業生涯

透過完成課程取得認證

開始
廣告
© . All rights reserved.