Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 446
Ax. Avatar asked Jan 24 '10 20:01

Ax.


3 Answers

$.fancybox.isOpen (bool) indicates, whether fancybox is open.

like image 93
tillsanders Avatar answered Oct 05 '22 04:10

tillsanders


Answer for 2018 December.

if ($('.fancybox-content').length == 0) {
    //there is no fancybox opened at all
}

Details:

    function checkf()
    {
        if ($('.fancybox-content').length == 0) {
            alert('there is no fancybox opened at all.');
        }
        else
        {
            alert('there is a fancybox opened.');
        }
    }
    $("#ffbox").click(function()
    {
        setTimeout(checkf,1000);
    });
    checkf();
    <head>
        <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.css" />
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="//cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/jquery.fancybox.min.js"></script>
    </head>
    <body>
        <a data-fancybox data-options='{"iframe" : {"css" : {"width" : "80%", "height" : "80%"}}}' href="https://www.google.com/maps/search/?api=1&query=China" class="btn btn-primary" id="ffbox">Display Google Map</a>
    </body>
like image 44
Y P Avatar answered Oct 05 '22 04:10

Y P


If you're looking for a way to determine whether fancybox is open or not (instead of an event that is fired upon opening fancybox) then as of fancybox v2 you can use the $.fancybox.isOpen property. It's not documented (at least I didn't find any reference) but it works.

Example:

if(!$.fancybox.isOpen) {
    $.fancybox.open({
        href: '#newsletter-campaign-popup',
        height: 385,
        width: 510,
        type: 'inline'
    });
}

The example above prevents opening a second fancybox if one is already open.

like image 39
Attila Fulop Avatar answered Oct 05 '22 02:10

Attila Fulop