.w-nav-overlay
to position: fixed
, full screen to avoid increasing page height.body { position: fixed; top: -scrollY }
on menu open and restore scroll position on close.You're trying to prevent background scrolling when a full-page .w-nav-overlay
dropdown is open, but standard solutions like overflow: hidden
on body/html
aren't working due to the overlay affecting page height.
.w-nav-overlay
often gets appended to the body by Webflow’s native navbar component.overflow: hidden
won't work if the overlay adds to scroll height instead of floating absolutely.Instead of just using overflow: hidden
, try the following combination when the dropdown is open:
body
to position: fixed
, width: 100%
, and preserve scrollY offset.Add this script:
<script> let scrollTop = 0; const navButton = document.querySelector('.w-nav-button'); const navOverlay = document.querySelector('.w-nav-overlay'); const disableScroll = () => { scrollTop = window.scrollY; document.body.style.position = 'fixed'; document.body.style.width = '100%'; document.body.style.top = `-${scrollTop}px`; }; const enableScroll = () => { document.body.style.position = ''; document.body.style.top = ''; document.body.style.width = ''; window.scrollTo(0, scrollTop); }; const observer = new MutationObserver(() => { const isOpen = navOverlay && getComputedStyle(navOverlay).display !== 'none'; isOpen ? disableScroll() : enableScroll(); }); if (navOverlay) { observer.observe(navOverlay, { attributes: true, attributeFilter: ['style'] }); }</script>
.w-nav-overlay
and disables/enables background scroll accordingly..w-nav-overlay
Positioning if NeededIf .w-nav-overlay
is pushing page height:
.w-nav-overlay
to position: fixed
, top: 0
, left: 0
, height: 100vh
, width: 100%
.You can apply this manually in Webflow:
.w-nav-overlay
in the Navigator.Fixed
, full screen.webflow.push
for Scroll LockWebflow.push
method is deprecated or limited to specific integrations (e.g., custom events).Set the .w-nav-overlay
to position: fixed
and use JavaScript to toggle body { position: fixed; }
when the menu opens. This approach prevents background scroll regardless of overlay height and avoids Webflow's default behaviors that break standard overflow: hidden
.