Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On fancybox open and close run functions

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.

like image 561
ccdavies Avatar asked Jun 05 '13 09:06

ccdavies


People also ask

How do I know if fancybox is loaded?

Here is the code: if ($('div#fancybox-frame:empty'). length >0) { alert('it is empty'); $.


1 Answers

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()
   }
});
like image 136
JFK Avatar answered Oct 04 '22 12:10

JFK