我在div中有一个视频元素。我只想将视频高度设置为完整的窗口。我发誓这是有效的,但在某个时刻我破了,不明白为什么......
jQuery选择器的长度= 0,可能是因为视频是在jQuery进行选择后加载的,但是直到2天前才开始工作
var $current_height = $(window).height();
var $videohome = $('video');
$videohome.height($current_height);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<div class="video full_height center"><a href="page">
<video class="full_height" poster="sites/all/themes/my_theme/img/cover_video1.jpg" onmouseover="this.play()" onmouseout="this.load()" id="video1" loop="true">
<source src="sites/default/files/videos/video1.mp4" type="video/mp4"></source>
<source src="sites/default/files/videos/video1.ogg" type="video/ogg"></source>
</video></a>
</div>
注释:
提前致谢
答案 0 :(得分:0)
尝试在js
中包裹$(document).ready(function() {})
,请参阅.ready()
$(document).ready(function() {
var $current_height = $(window).height();
var $videohome = $("video");
$videohome.height($current_height);
$videohome[0].load();
$videohome[0].play();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>
<div class="video full_height center">
<video class="full_height" id="video1" controls loop="true">
<source id="currentVID" src="http://html5multimedia.com/code/ch9/media/elephants-dream-medium.mp4" type="video/mp4">
</video>
</div>