2011-10-05 42 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一起工作过。所以你可以从我给出的链接中取消。我只是把我的整体想法。 –

相关问题