Javascript 使用JQuery从html5视频播放器触发事件
我想在我的html5视频播放器达到一定时间时显示一个div。 我能够在视频的结尾显示一个div,但我不确定在视频处于特定时间(如0:06)时如何显示divJavascript 使用JQuery从html5视频播放器触发事件,javascript,jquery,html,html5-video,Javascript,Jquery,Html,Html5 Video,我想在我的html5视频播放器达到一定时间时显示一个div。 我能够在视频的结尾显示一个div,但我不确定在视频处于特定时间(如0:06)时如何显示div <div id = "showdiv" style="display:none" align="center"> this is the message that will pop up. </div> <video id='myVideo' align="center" margin-top=
<div id = "showdiv" style="display:none" align="center">
this is the message that will pop up.
</div>
<video id='myVideo' align="center" margin-top="100px" class='video-js
vjs-default-skin' preload='auto' data-setup='{}' width='800' height='446'>
<source src='myVideo.mp4' type='video/mp4'l></source>
<script>
document.getElementById('myVideo').addEventListener('ended',myHandler,false);
function myHandler(e) {
if(!e) { e = window.event; }
$("#showdiv").toggle("slow");
}
</script>
这是将弹出的消息。
document.getElementById('myVideo').addEventListener('ended',myHandler,false);
函数myHandler(e){
如果(!e){e=window.event;}
$(“#showdiv”)。切换(“慢速”);
}
查看timeupdate
事件。
谢谢你的回答,但这似乎对我不起作用。必须与.addEventListener('timeupdate',runAtTime(myHandler,6),false)有关;它起作用了,但我的时间是:-01:00分每秒,也可能需要03:01:00这样的小时,那么我如何才能做到这一点呢?@UmairMalik将其转换为秒
h*60*60+m*60+s
非常好。非常感谢。
var runAtTime = function(handler, time) {
var wrapped = function() {
if(this.currentTime >= time) {
$(this).off('timeupdate', wrapped);
return handler.apply(this, arguments);
}
}
return wrapped;
};
$('#myVideo').on('timeupdate', runAtTime(myHandler, 3));