关闭模式后,Vimeo声音继续以引导模式播放

Vimeo sound keeps playing in bootstrap modal after closing the modal

本文关键字:模式 继续 播放 Vimeo 声音      更新时间:2023-09-26

在这个页面上,我们有多个指向vimeo视频的链接,这些视频都在同一引导模式中播放,并使用data-src填充模式。问题是,当模态关闭时,音频会继续播放。我可以运行什么脚本来停止音频播放?

页面就在这里,你可以点击顶部写着"安全文件共享"的图像来查看视频。

就我个人而言,我发现监听hidden.bs.modal事件并没有产生任何结果,相反hide.bs.modal对我有效。

奖金-无需点击vimeo API

  • 您需要将id添加到您的iframe中(在下面的示例中,id="iframe"
  • 侦听hide.bs.modal事件
  • 捕获变量的iframe-src
  • 将src设置为空字符串
  • 通过变量
    重新添加原始src…

       $('#orientation_video').on('hide.bs.modal', function () {
       // get the source of the iframe and save it
         var src = $(this).find('iframe').attr('src');
       // remove the src from the iframe
         $("iframe#iframe").attr('src','');
       // re-add the 
         $("iframe#iframe").attr('src', src);
       });