HTML DOM Video width 属性

htmlweb developmentfront end technology更新于 2024/5/18 0:12:17

HTML DOM Video width 属性返回/设置与媒体宽度(以像素为单位)对应的数字。

语法

以下是语法 −

返回 width 为数字 (px)

mediaObject.width

将宽度设置为数字 (px)

mediaObject.width = 数字

让我们看一个 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="http://www.tutorialspoint.com/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次 −


相关文章


有用资源