0
我見過幾個類似的問題,但不幸的是,沒有任何答案完全解決了我的問題。我有多個模式,每個模式都有不同的視頻iFrame。我希望視頻在模式關閉時停止播放。到目前爲止,我嘗試使用jQuery在用戶關閉模式時停止視頻。它可以工作,但由於某種原因,所有視頻都會被代碼中列出的第一個視頻所取代。有點奇怪。你可以在這裏看到它:http://tiffanymackins.com/gentrification/我沒有使用Bootstrap或任何框架。任何幫助是極大的讚賞。當Modal關閉時停止Youtube播放
這裏是我使用的代碼片段:
<a href="#modal-soulshine"><img id="soulshine-pin" class="pins" src="images/redPin.png"></a>
<div id="modal-soulshine" class="modal">
<div>
<a href="#close" title="Close" class="close"> close </a>
<h2> Soulshine Organics Farm: Jesse Leadbetter and Nicole Argento</h2>
<span class="ss-info"> Moved to Belmont in 2009</span>
<iframe id="player" width="450" height="253" src="https://www.youtube.com/embed/EpDEd9R005k" frameborder="0" allowfullscreen></iframe>
<p>....</p>
</div>
</div>
這是jQuery的從打:
/*Function built to take on search for youtube video in modal*/
function ytplayer() {
$('.modal iframe').attr("src", $(".modal iframe").attr(
"src"));
}
/*Function shuts down video when dismiss button is toggled*/
$('.close').click(function() {
$('#player').stop(this);
ytplayer();
});
如果您不使用Youtube API,您必須從源屬性中刪除視頻,如'$('。modal iframe')。attr(「src」,「」);' – adeneo
H毫米,這似乎只是擺脫了關閉模式後的視頻。 – tnicma
嗯,是的,這不是重點嗎?在無法控制的iFrame中停止視頻的唯一方法是更改iFrame的源代碼以消除內容。 – adeneo