I'm making a lightbox that is supposed to show a youtube video. The first problem that I encountered, was that my youtube video would still play when I closed the lightbox.
I then added: $('iframe').remove();
__
But then the iframe goes away offcourse , and only a blank box opens when i click the link activating the lightbox.
How do I make my iframe load again, after removing it?
Or, is there another way of making the video stop when I close down the lightbox?
My code is here:
<html>
<head>
<title>Youtube Lightbox</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<style type="text/css">
body
{
font-family: Arial;
}
.backdrop
{
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
background:#000;
opacity: .0;
filter:alpha(opacity=0);
z-index:50;
display:none;
}
.box
{
position:absolute;
top:20%;
left:30%;
width:500px;
height:300px;
background:#ffffff;
z-index:51;
padding:10px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow:0px 0px 5px #444444;
-webkit-box-shadow:0px 0px 5px #444444;
box-shadow:0px 0px 5px #444444;
display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$('.lightbox').click(function(){
$('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
$('.box').animate({'opacity':'1.00'}, 300, 'linear');
$('.backdrop, .box').css('display', 'block');
});
$('.backdrop').click(function(){
close_box();
});
});
function close_box()
{
$('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
$('.backdrop, .box').css('display', 'none');
$('iframe').remove();
});
}
</script>
</head>
<body>
<h1>This is a webpage...</h1>
<a href="#" class="lightbox">Open Youtube lightbox</a>
<div class="backdrop"></div>
<div class="box"><iframe width="500" height="300" src="http://www.youtube.com/embed/some/video" frameborder="0" allowfullscreen></iframe></div>
</body>
</html>
I hope that one you can help me out! :) Thanks.
Btw. I have researched the forum and found similar topics, but not an answer I could use, yet.