admin管理员组文章数量:1415111
I have this Jquery popup where I store an iframe with a youtube video. When I click the link, the popup opens and the User can click on the video and play it. Even though, when I click outside the popup, the popup closes, but the video/sound keeps playing! How can I avoid this?
Here's my HTML
<a href="#" id="showPopup">CLICK</a>
<div class="bg" style="display:none"></div>
<div class="popup" style="display:none">
<iframe width="480" height="360" src="//www.youtube/embed/Q_WHGV5bejk" frameborder="0" allowfullscreen></iframe>
</div>
my JS:
$(function(){
$("#showPopup").click(function(e){
e.stopPropagation();
$(".bg").toggle();
$(".popup").toggle();
});
$("body").click(function(){
$(".bg").toggle();
$(".popup").hide();
});
});
And the CSS:
.popup{
background-color:#E6E9F2;
position:absolute;
min-height:auto;
width:auto;
border: solid 2px #B9EAF0;
z-index: 1002;
}
.bg {
background-color:#111;
opacity: 0.65;
position:absolute;
z-index: 1000;
top:0px;
left:0px;
width:100%;
min-height:100%;
overflow:auto;
}
I alos created a Fiddle /
so, does anyone have a suggestion?
thanks in advance...
I have this Jquery popup where I store an iframe with a youtube video. When I click the link, the popup opens and the User can click on the video and play it. Even though, when I click outside the popup, the popup closes, but the video/sound keeps playing! How can I avoid this?
Here's my HTML
<a href="#" id="showPopup">CLICK</a>
<div class="bg" style="display:none"></div>
<div class="popup" style="display:none">
<iframe width="480" height="360" src="//www.youtube./embed/Q_WHGV5bejk" frameborder="0" allowfullscreen></iframe>
</div>
my JS:
$(function(){
$("#showPopup").click(function(e){
e.stopPropagation();
$(".bg").toggle();
$(".popup").toggle();
});
$("body").click(function(){
$(".bg").toggle();
$(".popup").hide();
});
});
And the CSS:
.popup{
background-color:#E6E9F2;
position:absolute;
min-height:auto;
width:auto;
border: solid 2px #B9EAF0;
z-index: 1002;
}
.bg {
background-color:#111;
opacity: 0.65;
position:absolute;
z-index: 1000;
top:0px;
left:0px;
width:100%;
min-height:100%;
overflow:auto;
}
I alos created a Fiddle http://jsfiddle/nLBZa/6/
so, does anyone have a suggestion?
thanks in advance...
Share Improve this question asked Apr 7, 2014 at 13:22 SHTSHT 7204 gold badges19 silver badges39 bronze badges2 Answers
Reset to default 3Try adding the following into your Jquery
$('#playerID').get(0).stopVideo();
EDIT: OK, so I thought that would work according to the API, anyways... Here is another solution:
var video = $("#player").attr("src");
$("#player").attr("src","");
$("#player").attr("src",video);
and your fiddle updated.
Assume, I have several different YT videos embedded in CSS only modals, like this:
<div id="video1" class="modalDialog">
<div>
<a href="#close" title="Close" class="videoclose">X</a>
<div id="video1_content"><iframe width="420" class="yvideo" id="video1_iframe" height="315" src="https://www.youtube./embed/_Qc4V_vEXdY?rel=0&showinfo=0&enablejsapi=1" frameborder="0" allowfullscreen></iframe></div>
</div>
I can dynamically unload (and therefor stop playing) a single video like so:
$('.videoclose').click(function( e ){
var contentdiv = $(this).next('div');
var iframe = $(contentdiv).find('iframe:first');
var video = $(iframe).attr("src");
$(iframe).attr("src","");
$(iframe).attr("src",video);
});
Thanks to Mike for the ignition ;-)
本文标签: javascriptJquery make Youtube video stop playing when clicking outside popupStack Overflow
版权声明:本文标题:javascript - Jquery make Youtube video stop playing when clicking outside popup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745223618a2648505.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论