HTML5中video-高度宽度

来源:互联网 发布:clasence 软件 编辑:程序博客网 时间:2024/05/19 23:12

实际上,在video标签中,有这样一个属性可以为我们使用:videoHeight&videoWidth,他获取的是video的高度和宽度(媒体本身),虽然不能直接使用,但我想,我们可以通过计算长宽比来解决这个问题。

通过加载后,获取元素实际高度,设置外层边框的高度

var myvObj = document.getElementById("myv");
myvObj.addEventListener("loadedmetadata", function () {
    console.log(this.videoHeight+" "+this.videoWidth);
    var height = $(this).height();
    console.log(height);
    $(".video-wrap").css('height',height);
});


 <div class="r-content">
        <div class="video-wrap" >
            <video  src="http://locolhost:9090/111.mp4"  width='100%'  controls="controls" class="video"
                    preload="metadata"  type="video/mp4" id="myv">
                Your browser does not support the video tag.
            </video>
        </div>
    </div>


0 0
原创粉丝点击