Bootstrap 3 and Youtube in Modal

后端 未结 18 1492
余生分开走
余生分开走 2020-12-07 07:05

I\'m trying to use the Modal feature from Bootstrap 3 to show my Youtube video. It works, but I can\'t click on any buttons in the Youtube video.

Any help on this?<

18条回答
  •  爱一瞬间的悲伤
    2020-12-07 07:16

    I put together this html/jQuery dynamic YouTube video modal script that auto plays the YouTube video when the trigger (link) is clicked, the trigger also contains the link to play. The script will find the native bootstrap modal call and open the shared modal template with the data from the trigger. See Below and let me know what you think. I would love to hear thoughts...

    HTML MODAL TRIGGER:

     VIDEO
    

    HTML MODAL VIDEO TEMPLATE:

    
    

    THE JQUERY FUNCTION:

    //FUNCTION TO GET AND AUTO PLAY YOUTUBE VIDEO FROM DATATAG
    function autoPlayYouTubeModal(){
      var trigger = $("body").find('[data-toggle="modal"]');
      trigger.click(function() {
        var theModal = $(this).data( "target" ),
        videoSRC = $(this).attr( "data-theVideo" ), 
        videoSRCauto = videoSRC+"?autoplay=1" ;
        $(theModal+' iframe').attr('src', videoSRCauto);
        $(theModal+' button.close').click(function () {
            $(theModal+' iframe').attr('src', videoSRC);
        });   
      });
    }
    

    THE FUNCTION CALL:

    $(document).ready(function(){
      autoPlayYouTubeModal();
    });
    

    The FIDDLE: http://jsfiddle.net/jeremykenedy/h8daS/1/

提交回复
热议问题