当用户点击视频播放时,使计时器停止

时间:2013-04-12 10:00:37

标签: javascript html css timer

我有另一个视频的视频。现在它的工作方式是,第一个视频在20秒后关闭并且用户将被发送到secound视频,但我希望当用户点击第一个视频上的播放时,计时器将停止并且不会在20之后关闭第一个视频秒。我该怎么办?

这是我的代码

<div id="luong_video_ads">
  <div id="luong_video_ads_mes">
    <div style="float:left;">
      <p style="color: #565656; font-family: sans-serif; font-size: 13px;">Ad will be closed   in <span id="luong_video_ads_c"></span> seconds
      </p>
    </div>
    <div style="float:left;margin-left:30px;">
      <input type="button" style="background: #ffe100; color: #474747; float: right; border:   1px solid #474747; border-radius: 5px; "value="Skip Ad" onclick="luong_video_ads_showMainVideo();">
    </div>
  </div>
  <br style="clear:both;"/>
  <div id="luong_video_ads_player">
  </div>
</div>
<script type="text/javascript">
luong_video_ads_time_wait = 30;
luong_video_ads_showed = 0;
luong_video_ads_embed = '<iframe src="http://player.vimeo.com/video/17618255"    width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen   allowFullScreen></iframe>';
luong_video_ads_main_embed = '<object width="420" height="315"><param name="movie"    value="http://www.youtube.com/v/Fcx-bRni7WM?   version=3&amp;hl=en_US&amp;rel=0&amp;autoplay=1"></param><param name="allowFullScreen"    value="true"></param><param name="allowscriptaccess" value="always"></param><embed    src="http://www.youtube.com/v/Fcx-bRni7WM?version=3&amp;hl=en_US&amp;rel=0&amp;autoplay=1"    type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always"    allowfullscreen="true"></embed></object>';
function luong_video_ads_showAdsVideo(){
  document.getElementById("luong_video_ads_c").innerHTML = luong_video_ads_time_wait;
  document.getElementById("luong_video_ads_player").innerHTML = luong_video_ads_embed;
}
function luong_video_ads_showMainVideo(){
  if (luong_video_ads_showed>0)
    return;
    luong_video_ads_showed = 1;
    document.getElementById("luong_video_ads_player").innerHTML =     luong_video_ads_main_embed;
    document.getElementById("luong_video_ads_mes").style.display = 'none';
}
luong_video_ads_int=self.setInterval(function(){luong_video_ads_clock()},1000);
function luong_video_ads_clock(){
  luong_video_ads_time_wait--;
    if (luong_video_ads_time_wait==0){
      luong_video_ads_showMainVideo();
    }
  document.getElementById("luong_video_ads_c").innerHTML = luong_video_ads_time_wait;
}
luong_video_ads_showAdsVideo();


</script>

感谢advence

2 个答案:

答案 0 :(得分:0)

我建议您查看类似http://videojs.com/的内容 - 您也可以嵌入vimeo。

这支持回调和事件监听器,因此您可以轻松地在播放/暂停和视频结束时运行功能。

答案 1 :(得分:0)

您可以通过删除计时器来删除计时器

window.clearInterval(intervalVariable);

有关更多选项,请参阅this

相关问题