还有另一种方法可以使用currentTime并为视频更改的每个时间定义一个函数。在HTML5视频元素顶部设置div,并在currentTime在3到4秒之间时修改该元素。
示例代码应该是这样的:
HTML:
Your browser does not support HTML5 video.
CSS:
#video_box{
position:relative;
}
#video_overlays {
position:absolute;
width:160px;
min-height:100px;
background:transparent;
z-index:300000;
bottom:50px;
left:10px;
text-align:center;
}
的JavaScript:
var vid = document.getElementById("myVideo");
// Assign an ontimeupdate event to the video element, and execute a function if the current playback position has changed
vid.ontimeupdate = function() {myFunction()};
function myFunction() {
//if currentTime is greater than 3 but less than 4, as in second 3+, go into if statement, otherwise go to else statement
if (vid.currentTime > 3 && vid.currentTime < 4) {
document.getElementById("video_overlays").innerHTML = '
Image Here
';}
else {
document.getElementById("video_overlays").innerHTML = '';
}
}
你可以第一个if语句停顿内该视频,然后显示一个图像,然后在视频开始一段时间后重新开始,如果这是您的意图,但此代码基本上是做这种事情的骨架。