【问题标题】:Vimeo sound keeps playing in bootstrap modal after closing the modal关闭模式后,Vimeo 声音继续在引导模式中播放
【发布时间】:2014-12-17 07:51:54
【问题描述】:
在这个页面上,我们有多个指向 vimeo 视频的链接,这些视频都在同一个引导模式中播放,并使用 data-src 填充模式。问题是当模式关闭时,音频会继续播放。我可以运行什么脚本来停止音频播放?
该页面是here,您可以通过单击顶部显示“安全文件共享”的图片来观看视频。
【问题讨论】:
标签:
javascript
html
twitter-bootstrap
vimeo
【解决方案1】:
我个人发现监听 hidden.bs.modal 事件并没有产生任何结果,而是 hide.bs.modal 为我工作。
奖励 - 无需使用 vimeo API
- 您需要在 iframe 中添加
id(在下面的示例中,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);
});