【问题标题】:Execute functions as HTML5 video plays在 HTML5 视频播放时执行功能
【发布时间】:2010-09-10 03:16:16
【问题描述】:

我正在尝试在 HTML5 视频达到特定秒值时执行基本功能。目前我没有任何运气,并希望我能在这里得到一些帮助。这是我目前使用的代码:

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
    });
});

我只想围绕视频做一个非常基本的内容交换,但到目前为止我运气不佳。提前感谢您的帮助!

【问题讨论】:

    标签: javascript jquery html5-video


    【解决方案1】:

    currentTime 是浮点值,而不是整数。去掉小数部分进行比较。

    var currentTime = parseInt(this.currentTime, 10);
    if(currentTime == 6) { 
        ..
    }
    

    【讨论】:

      【解决方案2】:

      这个 vanilla JavaScript 对我来说很好用:

      video.addEventListener('timeupdate', function(e) {
          如果 (e.target.currentTime == 6) ...
      }, false);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-09
        • 1970-01-01
        • 1970-01-01
        • 2016-08-07
        • 2012-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多