2011-10-05 37 views
0

我和我的員工一直在研究如何設置一個頁面來隱藏內容,該頁面出現在Youtube視頻的特定時間點。隱藏頁面內容,直到視頻中的具體時間

我們通過使用settimeout()函數很快就到達了那裏,但這只是經過的時間,而不是視頻中的時間。如果視頻暫停,例如,在指定的時間段之後,隱藏的內容無論如何都會出現。

這是我們到目前爲止的代碼:

<p> 
<script type="text/javascript">// <![CDATA[ 
    function showIt() { 
     document.getElementById("hid").style.display = "block"; 
    } 
    setTimeout("showIt()",30000); 
    // 1000 = 1 sec | 60000 is 1 minute 
    // ]]></script> 
</p> 
<p>{youtube}Yhwk5OorNPw&amp;rel=0&amp;autoplay=1&amp;showinfo=0&amp;version=3|640|390{/youtube}</p> 
<div id="hid" style="display: none;"> 
    <p style="text-align: center;"><span style="font-size: 32pt; color: #ff6600;"><strong><a target="_blank" href="http://www.youtube.com/watch?v=K80leSIhSD4"><span style="color: #ff6600;">HEY RICK - You can buy a Website Now!</span></a></strong></span></p> 
</div> 

如果你知道一個辦法把它引發與視頻到達一個特定的時間,這將是非常有益的!

回答

0

最好的方法是每秒鐘獲取當前YouTube視頻時間。

您可以使用setInterval每秒鐘調用該函數。在這個功能獲得當前的YouTube視頻時間和基於那做你的operations.I認爲這是一個可靠的方式

請檢查this答案。從答案你可以瞭解如何從YouTube播放器獲得當前播放時間。希望它可以幫助你

編輯

我猜你想顯示後的視頻30秒隱藏的內容。要獲得當前時間,您必須獲得YouTube視頻當前時間。要獲得當前時間,您必須使用YouTube API。有關API的更多信息,請參閱here

一旦獲得當前時間(你會得到單位爲秒),如果u使用API​​,你可以使用下面的邏輯來顯示使用我先前提供的代碼隱藏的內容

<script type="text/javascript"> 
var timerForLoadingResult= setInterval(showIt,1000);//call the fnction in every seconds. 
    function showIt() { 
     var currentTime=GetCurrentYoutubeTime(); // this function must return a current time in seconds 
     if(currentTime>=30) // i guess u need to show up after30 th second 
     { 
      document.getElementById("hid").style.display = "block"; 
      clearInterval(timerForLoadingResult);  //it will clear the timer, so the function will not excecute again 
     } 
     } 
    function GetCurrentYoutubeTime() 
    { 
     // fetch youtube video time using api . and return that value 
    } 
</script> 
+0

所以,你可以給我,我可以插入getCurrentTime代碼的例子嗎?謝謝! – user980876

+0

@用戶。看看edit.I還沒有和youtube api一起工作過。所以你可以從我給出的鏈接中取消。我只是把我的整體想法。 –

相關問題