我如何获得html5视频元素的宽度和高度 [英] How can I get the html5 video element's width and height
本文介绍了我如何获得html5视频元素的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的html5视频标签:
< video autobuffer =trueid =videocontrols = 真 >
< source src =some_url>< / scource>
< / video>
我没有在视频标签或css中定义明显的宽度和高度,视频包装会调整根据源视频大小,问题是,我怎样才能获得视频当前的宽度和高度?
我试过jquery
$('video')。css('width');
但它会返回原始尺寸:300px
我在页面中看到的是800px!
我该如何解决这个问题?
解决方案
$(function(){
$(#video)。bind(loadedmetadata,function(){
var width = this.videoWidth;
var height = this.videoHeight;
// ...
});
});
I have a simple html5 video tag:
<video autobuffer="true" id="video" controls="true">
<source src="some_url"></scource>
</video>
I have not define a obvious width and height in video tag or in css,the video wrapper would adjust according to the source video size,the problem is, how can I get the video current width and height? I have tried jquery
$('video').css('width');
but it return me the origin size :300px
what I see in the page is 800px!
How can I solve this problem?
解决方案
$(function () {
$("#video").bind("loadedmetadata", function () {
var width = this.videoWidth;
var height = this.videoHeight;
// ...
});
});
这篇关于我如何获得html5视频元素的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文