Explore Bato Web Agency Webflow Certified Partner Profile Explore Bato Web Agency Webflow Certified Partner Profile

Why does scrolling stop after opening and closing a mobile menu?

Illustration without a description Illustration without a description

Scrolling often stops after a mobile menu closes because the code that locked the page never restores every changed style. Common locks set overflow: hidden on html or body, fix the body in place, or attach a touchmove listener that prevents default behavior. Closing the menu must reverse the exact lock that opening it applied.

 

Inspect the computed styles on both html and body after closing. Look for overflow, position, height, inset and touch-action changes. Class-based locking is easier to reverse than a collection of inline styles. Remove the open class after the closing animation, but do not leave it waiting on an animation event that may never fire.

 

const root = document.documentElement;

function openMenu() {
root.classList.add('menu-open');
}

function closeMenu() {
root.classList.remove('menu-open');
}

/* CSS */
.menu-open {
overflow: hidden;
}

 

A fixed-body technique must save the current scroll position before opening. On close, remove the fixed positioning and restore that position. If the restoration runs before styles clear, or parses an empty top value, the page may jump or remain frozen. Keep the stored value in one variable and clear it after a successful restore.

 

Review event listeners when CSS looks correct. A document-level touchmove or wheel listener may still call preventDefault after the menu closes. Use an AbortController, a named handler or a stable cleanup function so the exact listener can be removed. Check that repeated open and close cycles do not register duplicate handlers.

 

Test the menu after scrolling halfway down a long page. Open and close it through the button, Escape key, overlay and navigation link. The page should return to the same position and scroll immediately. Repeat the cycle on iOS Safari and Android Chrome because body locking and visual viewport changes differ between mobile engines.