TJ Sherrill TJ Sherrill - 7 months ago 21
Javascript Question

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...

Answer

Fancybox has an onComplete callback.

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