|
8#
楼主 |
发表于 2016-9-21 03:14:53
|
只看该作者
<div style="width:100%;height:auto">
<video controls="controls" width="100%" preload="none" id="video1" src='../content/aa123.mp4'></video>
</div>
HTML5里面 video标签直接就是播放器了,播放器的height优先级永远高于width,
适配屏幕宽度,要么直接width直接设置为100%,要么执行以下代码
- <div style="width:100%;height:auto">
- <video controls="controls" width="100%" preload="none" id="video1" src='../content/aa123.mp4'></video>
- </div>
- <script type="text/javascript">
- //var videoElement = elements.find("video").first().attr("width", screenWidth).attr("height", screenWidth * 0.57);
- //videoElement.attr("width", screenWidth).attr("height", screenWidth * 0.57);
- var a = 0;
- function myResize() {
- var videoElement = document.getElementById("video1");
- videoElement.setAttribute("width", document.body.clientWidth); //获取body的宽度
- //videoElement.setAttribute("width", "100%"); //直接设置为100
- videoElement.setAttribute("height", document.body.clientWidth * 0.57);//设置高度为16:9
- a++;
- alert(a);
- }
- window.onresize = function () { setTimeout("myResize()", 100) };//这句话是为了兼容IE等浏览器,因为IE会两次触发onresize
- </script>
复制代码 |
|