Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent background scrolling on open of lightbox

I'm using Featherlight as a lightbox. One problem I have is that went it opens, the background remains scrollable. A fix that most lightboxes need is adding a class to the body with overflow:hidden; on it.

How can I do that on open of the lightbox, then remove the class on close?

like image 219
Rob Avatar asked Jan 30 '26 01:01

Rob


1 Answers

You can use the options on your plugin call by using of the beforeOpen and afterClose options like:

$.featherlight({
    beforeOpen: function() {
        document.body.style.overflow = 'hidden';
    },
    afterEnd: function() {
        document.body.style.overflow = '';
    }
});
like image 68
RWAM Avatar answered Jan 31 '26 15:01

RWAM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!