Twitter Bootstrap Modal stop Youtube video

后端 未结 21 1653
小蘑菇
小蘑菇 2020-11-27 11:57

I\'m very new to javascript and trying to use Twitter bootstrap to get a good looking website up and running quickly. I know this has something to do with jquery, but I\'m

21条回答
  •  一整个雨季
    2020-11-27 12:18

    My solution for 2 or more Youtube videos using the HTML data-* attribute. The video autoplays and stops when the modal is opened and closed.

    
    
    
    
    
    
    $('.modal').on('show.bs.modal', function (event) {
      $(this).find('iframe').attr("src", $(event.relatedTarget).data('url') );
    });
    
    $('.modal').on('hidden.bs.modal', function (e) {
        $(this).find('iframe').attr("src", "");
    });
    

    Here is a Codepen demo: https://codepen.io/danielblazquez/pen/oOxRJq

提交回复
热议问题