2015-05-17 94 views
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(); 
}); 
+0

如果您不使用Youtube API,您必须从源属性中删除视频,如'$('。modal iframe')。attr(“src”,“”);' – adeneo

+0

H毫米,这似乎只是摆脱了关闭模式后的视频。 – tnicma

+0

嗯,是的,这不是重点吗?在无法控制的iFrame中停止视频的唯一方法是更改​​iFrame的源代码以消除内容。 – adeneo

回答

0

停止视频试试吧

$('#modal-soulshine').on('hidden.bs.modal', function (e) { 

    $('#modal-soulshineiframe').removeAttr('src'); 

}); 
相关问题