5

Is there a way to run a function on Fancybox open and close?

I want to run a small function as the Fancybox trigger is fired, and when the Fancybox window is closed.

1 Answer 1

23

Fancybox has some callbacks for that so if running v1.3.4 you could do

$(".fancybox").fancybox({
   "onComplete": function(){
      // fancybox is open, run myFunct()
   },
   "onClosed": function(){
      // fancybox is closed, run myOtherFunct()
   }
});

for v2.1.x

$(".fancybox").fancybox({
   afterShow: function(){
      // fancybox is open, run myFunct()
   },
   afterClose: function(){
      // fancybox is closed, run myOtherFunct()
   }
});
2
  • Thank you JFK. Exactly what I was after.
    – ccdavies
    Jun 6, 2013 at 7:22
  • Just used it in 2.1.5 - works as expected! Thanks :-)
    – hardba11
    Feb 26, 2016 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.