【问题标题】:pause all html5 videos when play specific video jquery播放特定视频 jquery 时暂停所有 html5 视频
【发布时间】:2018-11-04 22:44:02
【问题描述】:

我在同一页面中有 10 个 html5 视频,

问题

当我点击不同的视频时,它们会同时播放...

  <div><video class="SetVideo"></video><button class="videoP"></button></div>
      <div><video class="SetVideo"></video><button class="videoP"></button></div>
  <div><video class="SetVideo"></video><button class="videoP"></button></div>
  <div><video class="SetVideo"></video><button class="videoP"></button></div>
  <div><video class="SetVideo"></video><button class="videoP"></button></div>
  <div><video class="SetVideo"></video><button class="videoP"></button></div>
  <div><video class="SetVideo"></video><button class="videoP"></button></div>

如何在特定视频中点击播放后暂停所有视频?

到目前为止我有这个,但什么都没有

  $(".videoP").on("click",function(){ 


   $(document).find("video").pause();
$(this).closest("div").find(".SetVideo").play();
 });

但它不起作用

【问题讨论】:

  • 您需要提供更多详细信息,您是如何嵌入视频的?

标签: javascript jquery


【解决方案1】:

这样的事情怎么样:

$(".videoP").on("click",function(){
    $('.SetVideo').trigger('pause');                       // Matches all videos with class videoP
    $(this).parent().find('.SetVideo').trigger('play');   // Should match the video corresponding to the clicked button
});

【讨论】:

  • 我正要提出同样的建议
  • 它只是暂停所有视频,包括我想播放的视频,不是pause()回调吗?
  • 虽然有点不清楚您是否希望他们在用户点击视频或点击按钮时暂停和播放(请参阅我的编辑)。
  • 当按钮被点击时。
  • @joe 我还没有实际尝试过,所以如果它不起作用,请告诉我。但这应该首先在所有视频上调用.pause(),然后在当前视频上调用.play()
猜你喜欢
  • 2012-05-06
  • 2016-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多