no-scroll
class in Webflow with overflow: hidden
and use JavaScript to add it to the <body>
when the nav menu opens and remove it when it closes.You're trying to disable scrolling when the navigation menu is open and re-enable it when closed, but class toggling issues are preventing it from working consistently.
overflow: hidden
) to the <body>
element.no-scroll
) and apply these styles:Place the following custom JavaScript in your project:
Project Settings > Custom Code > Footer — or in a Page Settings > Before
tag.
Code example:
(Replace .menu-button
and .menu-wrapper
with your actual class selectors)
```js
```
Webflow adds .w--open
automatically to the navMenu
when it is opened. This ensures the code correctly checks menu state.
To prevent scroll when the nav is open in Webflow, add a no-scroll
class to the body
using JavaScript when the menu opens and remove it when it closes. This works only if menu state is uniquely identified and selectors are not duplicated across elements.