Preventing body scrolling while a modal is active is essential for a seamless user experience. Here’s an updated approach in Webflow:
<script>
const openModal = () => {
document.body.style.overflow = 'hidden'; // **Locks scroll**
// Display your modal here, e.g., modal.style.display = 'block';
};
const closeModal = () => {
document.body.style.overflow = 'auto'; // **Re-enables scroll**
// Hide your modal here, e.g., modal.style.display = 'none';
};
</script>
openModal function when this element is clicked.
closeModal function on clicking the close button.
To prevent body scrolling while a modal is active in Webflow, use a combination of Webflow interactions and custom JavaScript. Set the body's overflow to 'hidden' when the modal opens and revert it back when closed. This approach ensures a smooth and user-friendly experience.