How can I add a no-scroll function when a CMS modal is open in Webflow?

Published on
September 22, 2023

To add a no-scroll function when a CMS modal is open in Webflow, you can follow these steps:

  1. Create a CMS collection: First, create a CMS collection in Webflow that will hold the content for your modals. This can be done by going to the CMS tab in the Webflow designer and clicking on "Add Collection".

  2. Design your modal: Design your modal using the Webflow Designer. You can use a modal component or div block to create the modal itself.

  3. Link the modal to the CMS collection: Link the modal to the CMS collection you created earlier. To do this, select the modal component or div block and go to the Settings panel on the right. Under "Collection", select the CMS collection you created and choose the appropriate fields to display in the modal.

  4. Add an interaction to show the modal: Add an interaction to show the modal when a certain action is triggered, such as clicking on a button or a link. To do this, select the trigger element (e.g., the button) and go to the Interactions panel. Create a new interaction and choose the "Show" action to display the modal.

  5. Add custom code to disable scrolling: To disable scrolling when the modal is open, you can add custom code to your site's footer or before the </body> tag. Use the following code:

body {  overflow: hidden;}

This code will hide the scrollbar when the modal is open, preventing the user from scrolling while the modal is active.

  1. Add custom code to enable scrolling: To re-enable scrolling when the modal is closed, you can add custom code to your site's footer or before the </body> tag. Use the following code:
body {  overflow: auto;}

This code will restore the scrollbar and allow the user to scroll again once the modal is closed.

That's it! Now, when you trigger the interaction to show the modal, the body of your website will have a no-scroll function, preventing the user from scrolling while the modal is open. When the modal is closed, scrolling will be enabled again.

Additional Questions:

  1. How do I create a CMS collection in Webflow?
  2. Can I customize the design of the modal in Webflow?
  3. Is it possible to add animations to the modal in Webflow?