0

I have jQuery animating a div with an embedded YouTube video in it.

I have it set so that when you close the video, the div hides and the movie stops. However, if I want to get the movie back I can't.

I was wondering if there was a callback that could reset the chain of events?

This is the jQuery I'm using:

$("#trigger2").click(function () {
    $( "#movie" ).animate({bottom: 0}, {duration:1000});
    $(".close").delay(1500).fadeIn('slow')
});
$(".close").click(function () {
    $("#movie").hide();
    var $player = $("#movie").detach();
});
Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
Greg
  • 567
  • 2
  • 14
  • 31
  • you can apply CSS on the div `display: none;` onclose and revert back it by `display: visible`. Dont know if it would be work, you can make e try – Kaidul Apr 19 '13 at 19:13

2 Answers2

1

$("#movie").detach(); is removing #movie from the DOM, so you can't show it again. if you can't stop the video player in another way, keep detach, and append it to show it.

jQuery:

$("#trigger2").click(function () {
    var movdiv = "<div id='movie'><p>movie box</p><a class='close'>Close</a></div>";
    $(movdiv).appendTo("body").animate({bottom: 0}, {duration:1000});
    $(".close").delay(1500).fadeIn('slow');
    $(".close").click(function () { $("#movie").detach(); });
});

Fiddle: http://jsfiddle.net/D4rXa/

Mooseman
  • 18,763
  • 14
  • 70
  • 93
0

You can't, The only way to get it back would be to reinitialize your div(with video) the way you initialized it first.

You can try appending your player that way - (after detaching) - .detach()

 var p;
 $(".close").click(function () {
        $("#movie").hide();
         p = $("#movie").detach();
 });

attach player again into DOM

p.appendTo('body');
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
  • I've been toying with this, wasn't 100% on how to get it to work. I've since reverted back to my original code only now it doesn't work at all! I'm relatively new to this type of script....did it somehow completely remove it? – Greg Apr 19 '13 at 20:03