当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Stop Youtube from playing when Modal is closed

问题描述:

I've seen a few questions similar, but unfortunately, none of the answers have fixed my issue exactly. I have multiple modals that have a different video iFrame in each one. I would like for the video to stop playing when the modal is closed. So far, I tried using jQuery to stop the video when the user closes the modal. It works, but for some reason, all of the videos get replaced with the first video listed in my code. It's weird. You can see it here: http://tiffanymackins.com/gentrification/ I'm not using Bootstrap or any framework. Any help is greatly appreciated.

Here is a snippet of the code i'm using:

<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>

And this is the jQuery to stop the video from playing.:

/*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();

});

分享给朋友:
您可能感兴趣的文章:
随机阅读: