简体   繁体   English

如何在调整大小事件中获取HTML5视频宽度?

[英]How to get html5 video width on resize event?

I have this simple video player: 我有一个简单的视频播放器:

<video id="v" controls width="640px" src="VIDEOHERE">
    <p>Your user agent does not support the HTML5 Video element.</p>
</video>

And this script: 这个脚本:

    <script>
       var v = document.getElementById("v");
       v.addEventListener( "resize", function (e) {
           var width = this.videoWidth,
               height = this.videoHeight;
               alert(width);
       }, false );
    </script>

I would like to get the actual width and height of the video when the user clicked on the resize button and its resized. 当用户单击调整大小按钮并调整其大小时,我想获取视频的实际宽度和高度。

Actually I'm trying to manage an overlay advertisement on this player. 实际上,我正在尝试在此播放器上管理重叠式广告。 I have already made the overlay, but when I resize the video I need to resize the overlay too, but now I only get the actual width when my page load. 我已经制作了叠加层,但是当我调整视频的大小时,我也需要调整叠加层的大小,但是现在我只有在页面加载时才得到实际的宽度。

I don't know if there's a fullscreen event on the video player. 我不知道视频播放器上是否有fullscreen事件。 You can try the default browser full screen, with the following code: 您可以使用以下代码尝试使用默认浏览器全屏显示:

$(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange', function() {
    console.log('Do something when user goes into full screen mode');
});

More details on this on: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode 有关此内容的更多详细信息,请访问: https : //developer.mozilla.org/zh-CN/docs/Web/Guide/API/DOM/Using_full_screen_mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM