Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính width của Video trong HTML DOM


Thuộc tính width của đối tượng Video trong HTML DOM trả về hoặc thiết lập một số tương ứng với chiều rộng (tính bằng pixel) của phương tiện.

Cú pháp

Trả về width dưới dạng số (px):

mediaObject.width

Thiết lập width thành một số (px):

mediaObject.width = number

Ví dụ

Ví dụ minh họa thuộc tính 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://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>          <input type="button" onclick="getTrackDetails()" value="Video không hiển thị">          <div id="divDisplay"></div>       </fieldset>    </form>    <script>       var divDisplay = document.getElementById("divDisplay");       var demo = document.getElementById("demo");       function getTrackDetails() {          demo.width += 50;          divDisplay.textContent = 'Chiều rộng video: '+demo.width;       }    </script> </body> </html>

Kết quả

Trước khi nhấn nút „Video không hiển thị“:

Thuộc tính width của Video trong HTML DOM

Nhấn nút „Video không hiển thị“ 3 lần:

Thuộc tính width của Video trong HTML DOM