Search code examples
jqueryfancybox

Fancybox - Overlay click, Esc and close button


Using fancybox modal window for our application.

$.fancybox.open($('#fancybox-modal'));

to prevent user click close button, esc option and click outside close window.

But, functions inside opt is not working as expected.

Not sure which line of code is missing.

Thanks

$.fancybox.open({
 src: '#fancybox-modal',
 opts : {
   closeBtn  : false,
   closeClick  : false,
   helpers : { 
    overlay : {closeClick: false} 
   },
   keys : {
     close  : null
   }
  }
});

Solution

  • Simply use modal option to make a true modal,

    $.fancybox.open({
      src: $('#fancybox-modal'),
      type: 'inline',
      modal : true
    });
    

    Demo - https://codepen.io/anon/pen/QeEOea?editors=1010

    Tip: use data-fancybox-close data attribute to make any element act as close button