我想在视频达到 5 秒或更长时间后触发事件,但我的代码遇到了一些问题。
.HTML:
<video id="video1" controls>
<source src="media/video.m4v" type="video/mp4" />
<source src="media/video.webm" type="video/webm" />
<source src="media/video.ogg" type="video/ogg" />
<p> Your browser does not support the HTML5 video feature. </p>
</video>
Javascript:
$(function () {
var video = $('#video1');
var time = 5;
function init () {
alert('Video is not available.');
}
$(video).on('timeupdate', function () {
if (video.currentTime >= time) {
init();
}
});
});
不幸的是,这不是一个有效的代码,有人知道我哪里出错了...?
你会得到undefined
,因为视频是没有属性currentTime
的jQuery对象,你可以像这样得到这个值
video.get(0).currentTime
或
this.currentTime
例
$(function () {
var video = $('#video1');
var time = 5;
function init () {
alert('Video is not available.');
}
video.on('timeupdate', function () {
if (video.get(0).currentTime >= time) {
init();
}
});
});