Javascript 如何使用html5元素调整视频大小?
我正在全屏播放一段视频。我正在使用html5元素,代码如下 javascript代码Javascript 如何使用html5元素调整视频大小?,javascript,jquery,html,Javascript,Jquery,Html,我正在全屏播放一段视频。我正在使用html5元素,代码如下 javascript代码 $('document').ready(function() { var o_vid_width=$('#vid1').width(); var o_vid_height=$('#vid1').height(); alert(o_vid_width);// output 300px var
$('document').ready(function()
{
var o_vid_width=$('#vid1').width();
var o_vid_height=$('#vid1').height();
alert(o_vid_width);// output 300px
var height = $(window).height();
var width = $(window).width();
alert(width)// //output 1280
if(o_vid_width<=width){
o_vid_width=width ;
alert(o_vid_height)// out put 150 px
}
});
}))
函数resizeToCover(){
//将视频视口设置为窗口大小
jQuery('#vid1').width(jQuery(window.width());
jQuery('#vid1').height(jQuery(window.height());
//使用水平/垂直的最大比例因子
var scale_h=jQuery(window).width()/vid_w_orig;
var scale\u v=jQuery(window).height()/vid\u h\u orig;
var标度=标度h>标度v?标度h:标度v;
//不允许缩放宽度<最小视频宽度
如果(scale*vid_w_orig
}HTML5全屏视频
<!doctype html>
<html lang="en">
<head>
<style type="text/css">
video{
margin: 0 auto; padding: 0;
}
body{
background-color:black;
}
</style>
</head>
<body>
<video id="myvideo" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$( document ).ready(function() {
var w = ($(window).width()) -20;
var h = ($(window).height()) -30;
$("#myvideo").height(h);
$("#myvideo").width(w);
});
$(window).resize(function() {
var w = ($(window).width()) -20;
var h = ($(window).height()) -30;
$("#myvideo").height(h);
$("#myvideo").width(w);
});
</script>
</body>
</html>
录像带{
边距:0自动;填充:0;
}
身体{
背景色:黑色;
}
您的浏览器不支持视频标记。
$(文档).ready(函数(){
var w=($(窗口).width())-20;
var h=($(窗口).height())-30;
$(#myvideo”)。高度(h);
$(“myvideo”)。宽度(w);
});
$(窗口)。调整大小(函数(){
var w=($(窗口).width())-20;
var h=($(窗口).height())-30;
$(#myvideo”)。高度(h);
$(“myvideo”)。宽度(w);
});
如果您有视频大小,请按以下方式操作:
var d = $(window),
e = $(".secao"),
f = e.children("div.video"),
b, c, j = 1920, k = 1200,
l = d.width(),
winH = d.height(),
winH = winH > 600 ? winH : 600,
c = Math.max(l / j, winH / k),
b = Math.round(k * c) + "px";
f.children("video").css({
height: b
})
});
并将溢出设置为隐藏
div#intro.secao {
background-color: #000000;
height: 100%;
overflow: hidden;
position: relative;
}
但是您正在警告o_vid_height的值???重复:您只更改变量的值。它们拥有视频大小的快照。如果您更改变量,这将不会影响视频。不,它的工作方式与我希望的完全不同,它在左侧和右侧留有边距,当我减小窗口大小时,它只在左侧显示精氨酸。您必须在调整windows事件$(window)的大小时设置宽度和高度。调整大小(函数(){});简单的黑客改变背景颜色为黑色,使其像全屏
<!doctype html>
<html lang="en">
<head>
<style type="text/css">
video{
margin: 0 auto; padding: 0;
}
body{
background-color:black;
}
</style>
</head>
<body>
<video id="myvideo" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$( document ).ready(function() {
var w = ($(window).width()) -20;
var h = ($(window).height()) -30;
$("#myvideo").height(h);
$("#myvideo").width(w);
});
$(window).resize(function() {
var w = ($(window).width()) -20;
var h = ($(window).height()) -30;
$("#myvideo").height(h);
$("#myvideo").width(w);
});
</script>
</body>
</html>
var d = $(window),
e = $(".secao"),
f = e.children("div.video"),
b, c, j = 1920, k = 1200,
l = d.width(),
winH = d.height(),
winH = winH > 600 ? winH : 600,
c = Math.max(l / j, winH / k),
b = Math.round(k * c) + "px";
f.children("video").css({
height: b
})
});
div#intro.secao {
background-color: #000000;
height: 100%;
overflow: hidden;
position: relative;
}