单击时自动在模态中播放视频

Auto play video in Modal on click

我目前有一个视频在单击按钮时以模式 window 打开。 如何在模式 window 打开时自动播放视频?

我正在使用的模式脚本称为 'Remodal',可在此处找到 http://vodkabears.github.io/remodal/

===================

FIDDLE

https://jsfiddle.net/tsdev/o4ndexuw/1/

===================

HTML

    <!-- 
    Button
    ================================================================================== -->

    <button class="image-button" onclick="window.location.href='#modal'">
        <span class="label">Watch Careers Video</span>
        <span class="icon flaticon-arrow"></span>
    </button>


    <!-- 
    Video Modal
    ================================================================================== -->


    <div class="remodal" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
      <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>

        <div class="video-container clearfix">

            <div class="video clearfix">
                <embed width="200" height="113" src="https://www.youtube.com/embed/xxxxxx" frameborder="0" allowfullscreen></embed>                                
            </div>

        </div>

    </div>

JQUERY

    <script src="<?php bloginfo('template_directory'); ?>/templates/careers/plugins/remodal/remodal.js"></script>

    <script>

      var stopVideo = function ( element ) {
          var iframe = element.querySelector( 'embed');
          var video = element.querySelector( 'video' );
          if ( iframe !== null ) {
              var iframeSrc = iframe.src;
              iframe.src = iframeSrc;
          }
          if ( video !== null ) {
              video.play();
          }
      };


      $('.remodal-close, .remodal-overlay').click(function(){
        var id = this.id || this.getAttribute( 'data-id' );
        var modal = document.querySelector( id );
        //closePopup();
        stopVideo( modal );
      });


      //  The second way to initialize:
      /*$('[data-remodal-id=modal2]').remodal({
        modifier: 'with-red-theme'
      });*/

    </script>

尝试像这样在您的视频后面添加“?autoplay=1”link:

https://www.youtube.com/embed/zrncfNIgc1s?autoplay=1