2010-09-10 117 views
2

我試圖獲得一個基本功能,當HTML5視頻達到特定的第二個值時執行。目前我還沒有運氣,希望能在這裏得到一些幫助。下面是我使用至今代碼:以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 
    }); 
}); 

我只想做周圍的視頻很基本的內容交換,但我沒有迄今爲止多少運氣。預先感謝任何幫助!

回答

1

currentTime是浮點值,而不是一個整數。刪除小數部分進行比較。

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

工作就像一個魅力,謝謝! – Andrew 2010-09-10 14:11:26

1

這香草的JavaScript,我工作得很好:

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