Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - fancybox and callback

I have problem with fancybox.
I want to write a function that will run when the fancybox opened. How and when to call the function?

Example:

function myFunc() {
    alert("Opened!");
}

$('.content a').fancybox({ 
    'hideOnContentClick': false ,
    'callBackOnShow': myFunc(), // This not working! It call function when page is loaded
    'frameWidth': 920,
    'frameHeight': 530
});
like image 836
sasa Avatar asked May 26 '09 12:05

sasa


People also ask

What is fancyBox jquery?

Fancybox saves you time and helps to easily create beautiful, modern overlay windows containing images, iframes, videos or any kind of HTML content.

How do I know if fancyBox is loaded?

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


2 Answers

Instead of myFunc() use myFunc. In javascript, a function with parens (and/or args) means you want to call it. A function name without them means you just want a reference to that function (which is probably what fancybox wants from you)

like image 188
Matt Briggs Avatar answered Oct 04 '22 17:10

Matt Briggs


This works

$("#element").fancybox({
    onStart     :   function() {
        return window.confirm('Continue?');
    },
    onCancel    :   function() {
        alert('Canceled!');
    },
    onComplete  :   function() {
        alert('Completed!');
    },
    onCleanup   :   function() {
        return window.confirm('Close?');
    },
    onClosed    :   function() {
        alert('Closed!');
    }
});
like image 25
Gabriel Avatar answered Oct 04 '22 18:10

Gabriel