【问题标题】:How to play one video in jQuery tab and stop others?如何在 jQuery 选项卡中播放一个视频并停止其他视频?
【发布时间】:2013-08-23 15:33:04
【问题描述】:

我有 4 个 Jquery 选项卡,每个选项卡中有 2 个视频。我如何同时播放一个视频并暂停所有其他视频?以及当我切换到新标签时如何让视频暂停?

这是代码Jsfiddle

/* play one video at a time */

$('video').bind('play', function() {
  activated = this;
  $('video').each(function() {
      if(this != activated) {
          this.pause();
      }
  });
});

/* get the active tab */
var active = $( "#issuestabs" ).tabs( "option", "active" ); 


/* pause all videos that are not in the active tab*/ 

if (!active) {
    $("video").each(function(){
        $(this).get(0).pause();
    });

}

谁能告诉我哪里出了问题?

谢谢!

【问题讨论】:

    标签: javascript jquery video


    【解决方案1】:

    你能用吗:

    $('.tab').on('click', function() {
      $('.tabcontent:hidden').find('video').each(function() {
        $(this).get(0).pause();
      });
    });
    

    (其中.tabcontent 是隐藏/显示的内容面板的名称,我显示的单击功能只是一个示例,因为我不知道您使用哪个库作为选项卡。)

    【讨论】:

    • 谢谢 Simey.me。我正在使用 Jquery UI 最新版本。
    • 我仍然无法让它工作。内容面板具有属性 aria-hidden="true" 我如何获取它而不是标签内容?
    • 它现在可以工作了,我忘了在 DOM 准备好之后放它。谢谢!
    猜你喜欢
    • 2018-01-21
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    相关资源
    最近更新 更多