Search code examples
jqueryfancybox

How to run an .animate immediately after fancybox function


I am trying to open a fancybox then run an animation on a z-indexed item. I want the .animate function to run automatically after the fancybox has opened.

to open a fancybox: $("#box").fancybox()

What I need to do is

$("#box").fancybox({
   $("#box").animate({left: "200"}, slow) 
});

But this clearly won't work. I am still learning jquery and js...


Solution

  • Fancybox has an onComplete callback.

    var box = $("#box")
    box.fancybox({
      'onComplete': function() { box.animate({left: "200"}, slow); }
    });