首页 > 解决方案 > 单击十字按钮后视频停止,但几秒钟后自动以模态方式重新开始

问题描述

我想以模态显示视频。视频显示完美,当我单击十字按钮时,模态隐藏并且视频停止。但几秒钟后,视频会自动从后端启动。

这是我的脚本模式

{{-- start modal --}}
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-body">
            <h1>Technology video</h1>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <iframe width="100%" height="350" src="https://www.youtube.com/embed/HBdcL7YsdBY?modestbranding=1&rel=0&controls=0&showinfo=0&html5=1&autoplay=1" frameborder="0" allowfullscreen></iframe>
        </div>
    </div>
</div>
</div>
{{-- end model  --}}
{{-- start script --}}
<script type="text/javascript">
    jQuery(document).ready(function(){

        jQuery('#videoModal').modal('show');

        jQuery("#videoModal").on('hidden.bs.modal', function (e) 
        {
            jQuery("#videoModal iframe").attr("src", jQuery("#videoModal iframe").attr("src"));
        });

    });
</script>
{{-- end script --}}

为什么视频会自动开始?如何阻止这个?

有人帮忙吗?

标签: javascriptjqueryhtmliframebootstrap-modal

解决方案


jQuery("#videoModal").on('hidden.bs.modal', function (e) 
    {
        jQuery("#videoModal iframe").attr("src", "https://www.youtube.com/embed/HBdcL7YsdBY?modestbranding=1&rel=0&controls=0&showinfo=0&html5=1&autoplay=0");
    });
jQuery("#videoModal").on('show.bs.modal', function (e) 
    {
        jQuery("#videoModal iframe").attr("src", "https://www.youtube.com/embed/HBdcL7YsdBY?modestbranding=1&rel=0&controls=0&showinfo=0&html5=1&autoplay=1");
    });

推荐阅读