Search code examples
javascriptfancybox

How to determine when fancybox is open?


I need to know that fancybox has been open up that to allow or deny another function to start.

Build-in functions Fancybox like 'onStart' or 'onClosed' not work.

I'm talking about version 1.3.0 RC2


Solution

  • The version your using apparently doesn't match the documentation; I looked at the source and saw the names of the options were different the the online docs. I just tested the following with 1.3RC2:

    $(document).ready(function() {
    
        function myStartFunction() { alert('fancy box opened'); }
    
        $("a#inline").fancybox({
            'onStart': myStartFunction
        });  
    });
    

    The option you're looking for is 'onStart' - the alert in myStartFunction goes off every time I open a box. I'm not sure when they changed the option but you can look at the source of any version you use at the bottom, and see what the option should be called.

    EDIT

    I just double checked on v1.2.5 - the version I use - and the callbacks are indeed named different. callbackOnStart works with 1.25 but, as I said, not 1.3