2013-04-04 27 views
2

我試圖設置一個側面導航在網頁上的不同時間播放主要功能視頻。設置鏈接在不同的時間播放視頻使用視頻-js

這是我的不工作代碼,顯然我使用video.js插件,它沒有這個側面導航效果很好。

HTML

<video id="myVideo" class="video-js vjs-default-skin box" controls preload="none" width="720" height="540" poster="images/myPoster.jpg" data-setup="{}"> 
    <source src="myVideo.mp4" type='video/mp4'> 
    <source src="myVideo.oggtheora.ogv" type='video/ogg'> 
</video> 



<a onClick="introduction()">Introduction</a> 
<a onClick="chapertOne()">Chapter One</a> 

JS

<script type="text/javascript"> 
var myPlayer = _V_("myVideo"); 
    function(introduction){ 
// Do something when the event is fired 
    myPlayer.currentTime(120); // 2 minutes into the video 
    myPlayer.play(); 
}; 
</script> 

<script type="text/javascript"> 
var myPlayer = _V_("myVideo"); 
    function(chapterOne){ 
// Do something when the event is fired 
    myPlayer.currentTime(440); // 4 minutes into the video 
    myPlayer.play(); 
}; 
</script> 
... 

的代碼是行不通的。當我按下鏈接時沒有任何反應。你認爲這是因爲它是一部很長的電影(約10米)。我也在考慮按照章節分割電影,然後爲每個鏈接加載一章。你認爲什麼是正確的做法?

+1

所以...你有什麼問題嗎? – Doorknob 2013-04-04 12:43:30

+0

我不知道如何video.js的作品,但** onClick =「介紹」**可能是錯誤的...... – 2013-04-04 12:49:04

+0

對不起,我認爲我的問題很清楚。我編輯了這個問題的最後部分來更好地解釋我自己。 @winner_joiner我也修正了onClick =「...」。 – Raul 2013-04-04 13:01:42

回答

3

function(chapterOne){ ... }此代碼創建尚未分配給任何變量的匿名函數。因此,也許你應該試試這個:

<script type="text/javascript"> 
    var myPlayer = _V_("myVideo"); 

    function introduction() { 
     // Do something when the event is fired 
     myPlayer.currentTime(120); // 2 minutes into the video 
     myPlayer.play(); 
    }; 

    function chapterOne() { 
     // Do something when the event is fired 
     myPlayer.currentTime(440); // 4 minutes into the video 
     myPlayer.play(); 
    }; 
</script> 

而且改變onClick屬性onclick

+0

現在工作得很好。現在整理出來了。謝謝ant_Ti! – Raul 2013-04-04 13:44:43