twitter-bootstrap - 具有Bootstrap Modal问题的YouTube视频

标签 twitter-bootstrap youtube modal-dialog

我的youtube视频无法播放,只是显示黑屏,这是一个小问题,我认为有一些小问题,但我找不到。

这也是页面的实时演示网址

http://chet.world/new-design/

 <section class="video section text-left  position-relative" id="f">
       <div class="vid-img section-img wow fadeInRight position-absolute">
         <div class="Video-content">
             <img src="assets/images/Video-back.png" alt="">

             <a class="mfp-iframe video-play-btn video-play-cus" data-toggle="modal" data-src="https://www.youtube.com/embed/nj3CaqBT7lY" data-target="#myModal"><img src="assets/images/play.png" alt=""></a>
         </div>
       </div>
        <div class="container">
            <div class="row align-items-center">
                <div class="col-lg-5 section-content wow fadeInLeft">
                   <div class="video-text">
                       <h1>The professional <br> development <br/> social network for <br/> 2019</h1>

            <a class="mfp-iframe video-play-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/nj3CaqBT7lY" data-target="#myModal">See what we’re building</a>
                   </div>
                </div>
            </div>

        </div>
    </section>
    <!--video-->




      <!-- Video Popup-->
   <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content"> 
             <button type="button" class="close" data-dismiss="modal">Close Video <img src="assets/images/close-btn.svg" alt=""></button>                
              <div class="modal-body">
                <!-- 16:9 aspect ratio -->
                    <div class="embed-responsive embed-responsive-16by9">
                      <iframe class="embed-responsive-item" src="" id="video"  allowscriptaccess="always">></iframe>
                    </div>
              </div>
            </div>
          </div>
        </div> 

这是javascript / jquery源代码。我认为是这样,但仍然显示黑屏。
<script type="text/javascript">

    $('.video-play-btn').click(function()
{
$videoSrc = $(".video-play-btn").data( "src" );
});

</script>

<script type="text/javascript">

    // when the modal is opened autoplay it  
    $('#myModal').on('shown.bs.modal', function (e)
    {
        // set the video src to autoplay and not to show related video. 
        console.log($("#video").attr('src',$videoSrc));

        //$("#video").attr('src',$videoSrc + "?rel=0&amp;showinfo=0&amp;modestbranding=1&amp;autoplay=1&amp;controls=0&amp'enablejsapi=1" ); 
    });//#myModal show

    // stop playing the youtube video when I close the modal
    $('#myModal').on('hide.bs.modal', function (e)
    {
        // a poor man's stop video
        $("#video").attr('src',$videoSrc); 
        //remove modal from DOM
        //$("#myModal").detach();
    });//#myModal close

</script>

最佳答案

您的来源在实时版本中未定义。您没有将YouTube视频的源添加到iframe。

它显示实时版本src上存在iframe错误:

src="undefined?rel=0&amp;amp;showinfo=0&amp;amp;modestbranding=1&amp;amp;autoplay=0"

应该类似于以下示例:
<iframe width="420" height="315" src="https://www.youtube.com/embed/tgbNymZ7vqY"></iframe>

检查您的iframe代码:
<iframe class="embed-responsive-item" src="" id="video"  allowscriptaccess="always">></iframe>

关于twitter-bootstrap - 具有Bootstrap Modal问题的YouTube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56531801/

相关文章:

css - 背景尺寸 : cover versus background-size: contain

html - 向右浮动将下一行向上移动

.net - Youtube .net api - 在播放列表中搜索

youtube - 是否有 YouTube API 可以为我提供有关视频的结构化元数据?

Javascript 翻转带有内容的 div

youtube - Youtube API:API与Google断开连接后,从API返回nolinkedyoutubeaccount错误

C# : Prevent child modal form from creating instance on taskbar

jquery - 在 jQuery UI 对话框上设置圆角类型

modal-dialog - 仅当用户单击关闭btn时,如何关闭Materialized模态?

html - 如何使按钮大小相同并在页面上居中?