Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable fancyBox 2 from closing when clicking the background

In fancyBox 2, is there a key/value I could set that will disable the lightbox from closing when the user clicks the background (semi-transparent black background)?

I only want to give them the option to click the actual (X) close button in the top right hand corner.

Any ideas?

Thanks.

like image 498
Mark Notton Avatar asked Mar 16 '12 05:03

Mark Notton


2 Answers

For version 2.x use

 $(".fancybox").fancybox({
    closeClick  : false, // prevents closing when clicking INSIDE fancybox
    helpers     : { 
        overlay : {closeClick: false} // prevents closing when clicking OUTSIDE fancybox
    }
 });

if closeClick is set to true (default) fancybox will close if clicking over the content so with these two combined options the only possible way to close fancybox is with the close (X) button

like image 108
JFK Avatar answered Oct 10 '22 02:10

JFK


This will disable closing fancybox when clicking on the overlay (the semi-transparent background)

    fancyEls.fancybox({
        helpers : { 
            overlay : {
                closeClick: false
            } // prevents closing when clicking OUTSIDE fancybox
        }
    });

This will disable all default click methods of closing fancybox

    fancyEls.fancybox({
        closeBtn : false,
        closeClick : false,
        helpers : { 
            overlay : {
                closeClick: false
            } // prevents closing when clicking OUTSIDE fancybox
        },
        keys : {
            close: null
        } // prevents close when clicking escape button
    });

And this will do the same as well as disabling slideshow functionality

    fancyEls.fancybox({
        modal : true //If set to true, will disable navigation and closing  
    });
like image 6
MrBizle Avatar answered Oct 10 '22 00:10

MrBizle