【问题标题】:Bootstrap Modal Video keeps playing when closedBootstrap 模态视频在关闭时继续播放
【发布时间】:2021-11-11 19:13:13
【问题描述】:

我使用 MySQL 和 PHP 编写了一个视频索引程序,并将视频发送到模式窗口。但是,当模态窗口关闭时,视频会继续播放。这是代码。我是这方面的新手,提前道歉。我已经在互联网上搜索了没有任何解决方案的答案。

 <a href"#" class="video" data-video="<?php echo $vidpath . $file_mp4_v3;?>" data-toggle="modal" data-target="#videoModal"><?php echo $movie_name_v3 ;?></a>


  <div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="videoModalLabel">Modal</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body justify-content-center">
                    <div class="video" id="divVideo">
                        <video autoplay id="myVideo" width="1280" height="720" controls="false" poster="" class="myvideo img-fluid">
                                <source src="" type="video/mp4" />
                            <source src="" type="video/ogv" />
                            <source src="" type="video/wmv" />
                <script>
                     
                </script>
                        </video>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(function() {
  $(".video").click(function () {
    var theModal = $(this).data("target"),
        videoSRC = $(this).attr("data-video"),
        videoSRCauto = videoSRC + "";
    $(theModal + ' source').attr('src', videoSRCauto);
    $(theModal + ' video').load();
    $(theModal + ' button.close').click(function () {
      $(theModal + ' source').attr('src', videoSRC);
    });
  });

})


</script>
   

【问题讨论】:

    标签: javascript php jquery video modal-dialog


    【解决方案1】:

    就像您将src 属性设置为开始播放视频一样,您可以将其清空以停止视频。

    您可以使用the modal bootstrap events hide.bs.modalhidden.bs.modal 来执行此操作。

    【讨论】:

    • 感谢您的回复,不胜感激。我已经尝试了上述 hide.bs.modal 或 hidden.bs.modal 函数的几种变体,但均未成功。我将把这个命令放在哪里以及如何正确编写脚本。感谢您的帮助,不胜感激。
    【解决方案2】:

    感谢您的回复,不胜感激。我已经尝试了上述 hide.bs.modal 或 hidden.bs.modal 函数的几种变体,但均未成功。我将把这个命令放在哪里以及如何正确编写脚本。 感谢您的帮助,不胜感激。

    【讨论】:

    • 如果您宁愿将此作为问题/答案的评论而不是独立的答案发布会更好。否则,此响应将被解释为对问题的回答。
    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    相关资源
    最近更新 更多