如何停止标签中的视频? [英] How to stop video in tab?
本文介绍了如何停止标签中的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网站上有一个标签界面,其中最后一个标签包含图片和 youtube 视频.一切正常,但是每次我切换标签时,视频都不会停止播放.有没有办法解决这个问题?提前致谢.
I have a tab interface on my website that contains images and a youtube video on the last tab. All works fine however everytime I switch tabs the video doesn't stop playing. Is there a way to fix this? Thanks in advance.
这是我得到的:
推荐答案
DEMO — 切换标签会暂停所有正在播放的视频.
DEMO — Switching tabs pauses any playing videos.
通过使用 YouTube Player API,您可以玩/暂停/停止视频.
By using the YouTube Player API, you can play/pause/stop videos.
<script src="//www.youtube.com/iframe_api"></script>
<iframe width="510" height="287" src="//www.youtube.com/embed/VIDEO_ID?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
<script>
$(function(){
$('iframe[src*="//www.youtube.com/embed/"]').each(function(i) {
this.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
});
});
</script>
注意 ?enablejsapi=1
查询字符串附加到 iframe
中的 YouTube 嵌入 URL.
Note the ?enablejsapi=1
query string appended to the YouTube embed URL in the iframe
.
这篇关于如何停止标签中的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文