Execute functions as HTML5 video plays
I'm trying to get a basic function to execute when an HTML5开发者_StackOverflow社区 video reaches a specific second value. Currently I haven't had any luck and was hoping that I could get some help here. Here's the code I'm using thus far:
jQuery(function(){
jQuery("video").bind("timeupdate", function() {
if(this.currentTime == "6") { alert("six seconds in"); }
// also tried the above line with the 6 not in quotes
});
});
I just want to do a really basic content swap around the video but am not having much luck thus far. Thanks in advance for any help!
currentTime
is a float value, not an integer. Remove the fractional part for the comparison.
var currentTime = parseInt(this.currentTime, 10);
if(currentTime == 6) {
..
}
This vanilla JavaScript works just fine for me:
video.addEventListener('timeupdate', function(e) { if (e.target.currentTime == 6) ... }, false);
精彩评论