Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Mobile menu won't close or scrolls page behind: how to fix it

PRF-169Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

On phones, your navigation usually sits behind a hamburger icon. Tapping it opens a full-screen or slide-in panel. This issue covers two related faults after the menu opens.

The two faults
  • The menu cannot be closed: the close icon does nothing, is hidden, sits off screen, or the menu stays open after you tap a link.
  • The page scrolls behind the menu: you swipe inside the menu and the page underneath moves instead, or the menu itself will not scroll when it is taller than the screen.

Why it costs you leads or sales

Where the visitor gets stuck
  1. Landing pageVisitor arrives from an ad
  2. Opens menuTaps the hamburger icon
  3. Menu stuckClose does nothing or page scrolls behind
  4. Form or checkoutNever reached

The menu opens, but the visitor cannot get past it.

How to check if your site has it

Test the menu on a real phone
  1. Open your site on a real iPhone and Android phone

    Use the browsers your visitors use: Safari on iOS and Chrome on Android. Narrow desktop windows often hide scroll and touch bugs.

  2. Open the menu and try to close it

    Tap the close icon, tap outside the panel, and tap a menu link. The menu should close and the right page or section should show.

  3. Swipe inside the menu

    The page behind should stay still. If the menu is long, the menu itself should scroll to its last item.

  4. Rotate the phone

    Landscape mode makes the menu shorter than its content, which exposes missing scrolling.

  5. Check the console

    In Chrome on desktop, open DevTools, switch on device mode, open the menu and look for red errors in the Console. A JavaScript error often stops the close handler from running.

How to fix it

Symptoms and likely causes
What you seeLikely causeFix
Close icon does nothingJavaScript error or a plugin conflictFix the console error, disable conflicting plugins or scripts
Close icon not visibleIcon hidden behind the header or off screenCheck z-index and position of the close button
Menu stays open after tapping a linkOne-page site or app-style navigation, no close on clickClose the menu in the link click handler
Page scrolls behind menuNo scroll lock on bodyAdd overflow hidden while the menu is open
Menu cannot scroll to last itemMenu taller than screen, fixed heightGive the panel max-height and overflow-y auto
Page stays locked after closingScroll lock class never removedRemove it on close, link tap and page change
Scroll lock and a scrollable menu panelcss
body.menu-open {
  overflow: hidden;
}

.mobile-menu {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 1000;
}
Open, close and always unlockjavascript
const body = document.body;
const menu = document.querySelector('.mobile-menu');
const openBtn = document.querySelector('.menu-open-btn');
const closeBtn = document.querySelector('.menu-close-btn');

function openMenu() {
  menu.hidden = false;
  body.classList.add('menu-open');
}
function closeMenu() {
  menu.hidden = true;
  body.classList.remove('menu-open');
}

openBtn.addEventListener('click', openMenu);
closeBtn.addEventListener('click', closeMenu);
menu.addEventListener('click', (e) => {
  if (e.target.closest('a')) closeMenu();
});
document.addEventListener('keydown', (e) => {
  if (e.key === 'Escape') closeMenu();
});
window.addEventListener('pageshow', closeMenu);
Fix by platform
  1. Find the conflict

    Switch to a default theme such as Twenty Twenty-Four on a staging copy. If the menu works, the theme is the cause. If not, deactivate plugins one by one, especially menu, popup and optimization plugins.

  2. Exclude menu scripts from optimization

    If you use a caching or minify plugin, exclude the theme's menu script from JavaScript delay, defer or combine, then clear the cache.

  3. Add the CSS fix

    Add the scroll-lock CSS in Appearance > Customize > Additional CSS, using your theme's menu class names. Check what your theme adds to the body when the menu opens.

Menu behaviour before and after

Broken

  • Close icon unresponsive
  • Page moves when you swipe the menu
  • Last menu items cut off
  • Body stays locked after navigating

Fixed

  • Close works by icon, link, backdrop and Escape
  • Page behind stays still
  • Menu scrolls on its own
  • Lock removed on every exit
Try the scroll lockInteractive
Scroll lock missing

No scroll lock

Leads or data lost

The visitor swipes inside the menu and the page underneath moves. They lose their place and may not find the close button.

Toggle to compare a menu without and with a body scroll lock.

How to confirm it's fixed

Retest on real devices
  • Open and close the menu five times in a row on iPhone Safari and Android Chrome.
  • Tap a menu link and confirm the menu closes and the page can scroll again.
  • Swipe inside the open menu and confirm the page behind does not move.
  • Rotate to landscape and confirm every menu item can be reached.
  • Use the browser back button after opening a link and confirm the page is not stuck locked.
  • Check the console shows no new errors.

How to prevent it happening again

Habits that stop regressions
  • Test the mobile menu on a real phone after every theme, plugin or app update.
  • Add a menu check to your release checklist for design and header changes.
  • Test on a staging copy before publishing new popups, chat widgets or sticky bars.
  • Keep one close function that always removes the scroll lock.
  • Avoid delaying or combining the menu script in optimization settings.

How FunnelGuard handles this

Questions people ask

Why does my mobile menu not close?

Usually a JavaScript error, a plugin or app conflict, or a close button hidden behind another element. Open the browser console in device mode to look for errors, then disable plugins or apps one at a time to find the conflict.

How do I stop the page scrolling behind my mobile menu?

Add a class to the body when the menu opens and set overflow: hidden on it. Remove the class when the menu closes. Add overscroll-behavior: contain to the menu panel so swipes do not pass through to the page.

Why does the page stay locked after I close the menu?

The scroll lock class or inline style is not being removed on every exit path. Make sure closing by icon, link tap, backdrop tap and page navigation all call the same function that removes the lock.

Why does my mobile menu work on desktop but not on my phone?

Desktop narrow windows do not reproduce touch events, iOS Safari address bar behaviour or real viewport height. Test on a real device, and use 100dvh instead of 100vh so the menu fits the visible screen.

Why can't I scroll to the bottom of my mobile menu?

The menu panel is probably taller than the screen with no scrolling of its own. Give it a fixed position, a height of 100dvh and overflow-y: auto so long menus scroll inside the panel.

Does a broken mobile menu affect conversions?

Yes, if visitors rely on it to reach pricing, booking or checkout pages and cannot get past it. The impact depends on how much of your traffic is on mobile and how much of it uses the menu.

Does FunnelGuard check if my mobile menu can be closed?

No, not yet. It is a possible future check. FunnelGuard currently runs your customer journeys, tracking and lead delivery checks, so test the mobile menu manually on real phones after site changes.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.