HTML5视频 - 在特定视频时间显示div
问题描述:
我正在尝试在视频播放的某个时间显示div,但下面的代码无效。有人可以告诉我这样做的正确方法是什么(不使用爆米花......)?
I'm trying to show a div at a certain time in the video playback, but the code below is not working. Can someone please tell me what would be the correct way of doing this (not using popcorn...)?
$(document).ready(function() {
$("#element_1").hide();
var v1 = document.getElementsByTagName('video')[0];
v1.addEventListener("timeupdate", function() {
videoTime = v1.currentTime;
});
if(videoTime == 10){
$("#element_1").show()
}
});
也尝试了这个但没有去...
Also tried this but no go...
$(document).ready(function() {
$("#element_1").hide();
document.getElementsByTagName('video').addEventListener("timeupdate", function() {
if(this.currentTime > 10 * 60) {
$("#element_1").show()
}
});
});
答
这有效......
$(document).ready(function() {
$("#element_1").hide();
document.getElementById('v1').addEventListener("timeupdate", function() {
if(this.currentTime > 10) {
$("#element_1").show()
}
});
});
和
<video id="v1" width="320" height="240" controls>
<source src="needles.mp4" type="video/mp4">
<source src="needles.ogg" type="video/ogg">
</video>
<div id="element_1">Element 1</div>