【问题标题】:Embedded Youtube video keeps playing after dismissed嵌入的 Youtube 视频在关闭后继续播放
【发布时间】:2015-02-26 10:10:14
【问题描述】:

关于如何在按下关闭按钮甚至关闭模态视图后停止 youtube 视频在后台连续播放的任何建议?

<a data-toggle="modal" href="#videoModal">
    <img class="img-responsive img-rounded" src="http://iconshots.com/wp-content/uploads/2010/01/final1.jpg">
</a>

<div class="modal fade" id="videoModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Learn how to make this app!</h4>
            </div>
            <div class="modal-body">
                <iframe width="500" height="281" src="http://youtu.be/GWPc6EDwv8k" frameborder="0"></iframe>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

  • this的可能重复
  • 不,不幸的是它对我不起作用

标签: jquery twitter-bootstrap youtube youtube-api bootstrap-modal


【解决方案1】:

所以我发现这个在线进行了大量的研究,这对我有用。我创建了一个单独的 js 文件,然后将其链接到页面。

    /*Function built to take on search for youtube video in modal*/
function ytplayer() {
    $('#videoModal iframe').attr("src", $("#videoModal iframe").attr(
        "src"));
}  
/*Function shuts down video when dismiss button is toggled*/
$('.close').click(function() {
    $('#videoModal').hide();
    ytplayer();
});

/*Function shuts down video when modal background is toggled*/
$('#videoModal').on('hidden.bs.modal', function() {
    ytplayer();
});

【讨论】:

    【解决方案2】:

    使用一些 jQuery 你可以做这样的事情:

    $('#someButton').click(function(){
       $('#playerID').get(0).stopVideo();
    )};
    

    这是与您的问题相关的帖子,希望它可以为您指明正确的方向:Youtube api - stop video

    【讨论】:

    • 什么方法是“停止视频”我在 mdn 中查找它并且 jquery api 没有显示搜索结果。有什么方法可以详细说明一下吗?
    • 刚刚用相关的 stackoverflow 链接更新了我的答案,希望对您有所帮助
    猜你喜欢
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 2023-03-13
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    相关资源
    最近更新 更多