Ich habe zwei Videos auf der gleichen Seite und sie öffnen in einem Iframe. Wenn ich das Popup schließe, wird das Video nicht gestoppt. Es spielt weiter. Aufgrund von Umständen, die außerhalb meiner Kontrolle liegen, muss ich mit den Videos innerhalb von iframes arbeiten.Stoppen Sie das Video von der Wiedergabe
Könnte jemand helfen, unter dem Code für das gleiche ist:
jQuery:
$("[data-media]").on("click", function(e) {
e.preventDefault();
var $this = $(this);
var videoUrl = $this.attr("data-media");
var popup = $this.attr("href");
var $popupIframe = $(popup).find("iframe");
$popupIframe.attr("src", videoUrl);
var left = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var left = left/2 - 340;
var top = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var top = top/2 - 180;
document.getElementById("vid").style.top = top + "px";
document.getElementById("vid").style.left = left + "px";
document.getElementById("vid1").style.top = top + "px";
document.getElementById("vid1").style.left = left + "px";
$this.closest(".page").addClass("show-popup");
});
$(".popup").on("click", function(e) {
e.preventDefault();
e.stopPropagation();
$(".page").removeClass("show-popup");
});
$(".popup > iframe").on("click", function(e) {
e.stopPropagation();
});
HTML:
<div class="popup" id="media-popup"> <!-- video embedded -->
<iframe id="vid" src="http://player.vimeo.com/video/1212121210?title=0&byline=0&portrait=0" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<iframe class="show-2" style="display: none;" id="vid1" src="http://player.vimeo.com/video/112324343?title=0&byline=0&portrait=0" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<a class="video-close" href="#0"></a>
</div><!-- popup -->
<a id="video" data-media="//www.vimeo.com/134243242">video 1</a>
<a id="video" class="video-2" data-media="//www.vimeo.com/00102102">Video 2</a>
Mögliche doppelte: http://stackoverflow.com/questions/13598423/stop-all-playing-iframe- videos-on-click-a-link-javascript –
Wenn möglich, würde ich auch vorschlagen, dass du 'video' Elemente verwendest, anstatt die' src' des 'iframe' direkt auf das Video zu setzen, da du dadurch viel mehr Kontrolle hast - du Holen Sie die Methode 'pause()' für eins. –
@RoryMcCrossan können Sie bitte ein Beispiel teilen? das könnte mir helfen. – Bob