Disable fancyBox 2 from closing when clicking the background

后端 未结 5 1799
走了就别回头了
走了就别回头了 2021-01-04 02:26

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)?

相关标签:
5条回答
  • 2021-01-04 03:00

    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  
        });
    
    0 讨论(0)
  • 2021-01-04 03:00

    To prevent close button- use:

    defaults: {  closeBtn   : false,}
    

    To prevent overlay close - use :

    F.helpers.overlay = {
            defaults : {closeClick : false,      // if true, fancyBox will be closed when user clicks on the overlay }}
    

    To prevent escape click close :

    defaults: {keys  : {//close  : [27], // escape key
                    close  : null, } }
    
    0 讨论(0)
  • 2021-01-04 03:05

    try this let adduser be my target selector

    $('.adduser').fancybox({
    'hideOnOverlayClick': false
    });
    
    0 讨论(0)
  • 2021-01-04 03:08

    According to the Fancybox site API you could/should use

    $.fancybox({
       ...
       'hideOnOverlayClick' : false,
       ...
    });
    
    0 讨论(0)
  • 2021-01-04 03:16

    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

    0 讨论(0)
提交回复
热议问题