.lightbox-open { overflow: hidden; }..lightbox-open class on the body when the lightbox is opened and remove it when closed. When using a Webflow lightbox, you may want to freeze the body content while allowing the lightbox content to scroll separately for better user experience. Here's how you can achieve that:
<style> tag with a rule to prevent body scrolling when the lightbox is open:```css
.lightbox-open {
overflow: hidden;
}
```
.lightbox-open class to the body when the lightbox is opened:```javascript
document.addEventListener('DOMContentLoaded', function() {
const lightboxLinks = document.querySelectorAll('.w-lightbox');
if (lightboxLinks.length) {
lightboxLinks.forEach(link => {
link.addEventListener('click', () => {
document.body.classList.add('lightbox-open');
});
});
}
// Listen for when the lightbox closes
window.addEventListener('click', (event) => {
if (event.target.closest('.w-lightbox') === null) {
document.body.classList.remove('lightbox-open');
}
});
});
```
By adding minimal CSS and custom JavaScript, you can freeze the body content while allowing the Webflow lightbox content to scroll. Adding a CSS rule .lightbox-open to control overflow and a JavaScript event listener to manage class toggling achieves this separation of scrolling behaviors effectively.