vendredi 1 juillet 2016

Stop video when modal is closed

I'm trying to stop videos in modals from playing when they have been closed. The problem is that my modal script moves the modal from its original place to just before the closing </body> tag. So with stop video script technically above the modal window the video never stop playing after modal is closed. Here's the modal script i use https://github.com/VodkaBears/Remodal JQUERY TO STOP VIDEO var stopVideo = function ( element ) { var video = element.querySelector( 'video' ); // script stops here with this error message: (index):684 Uncaught TypeError: Cannot read property 'querySelector' of null. if ( video !== null ) { video.stop(); } }; $('.remodal-close').click(function(){ var id = this.id || this.getAttribute( 'data-remodal-id' ); var modal = document.querySelector( id ); //closePopup(); console.log("has video stopped? 1"); stopVideo( modal ); console.log("has video stopped? 2"); }); HTML FOR 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/xxxxxxxx?autoplay=1" frameborder="0" allowfullscreen> </div> </div> </div>

Aucun commentaire:

Enregistrer un commentaire