Ich versuche, Videos in Modals zu stoppen, wenn sie geschlossen wurden. Das Problem ist, dass mein modales Skript das Modal von seinem ursprünglichen Platz zu dem schließenden -Tag verschiebt. Mit dem Stop-Video-Skript über dem modalen Fenster hört das Video also nie auf zu spielen, nachdem Modal geschlossen wurde.Stoppen Sie das Video, wenn Modal geschlossen ist
Hier ist das modale Skript i https://github.com/VodkaBears/Remodal verwenden
JQUERY 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 Modal
ZU STOPPEN<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>