Close button of off-canvas menu scrolls to top
-
Thank you for that beautiful and user-friendly theme!
I show a menu with URL fragments as custom links, such as “#first”, ‘#second”. When I test it on a mobile screen with the off-canvas menu (Firefox), the page scrolls correctly to the corresponding anchor. But when I click the “X” to close the menu, the page jumps back to the top.
I managed to circumvent that issue by detaching the event from the
<a class="mobile-menu-close" href="#"> ... </a>
element (by cloning the element) and then re-attaching the same again with a short delay.const ready = (callback) => { if (document.readyState != "loading") callback(); else document.addEventListener("DOMContentLoaded", callback); } ready(() => { setTimeout(function(){ const closeButton = document.getElementsByClassName( 'mobile-menu-close' )[ 0 ]; const closeButtonClone = closeButton.cloneNode(true); closeButton.parentNode.replaceChild(closeButtonClone, closeButton); const offCanvas = document.getElementsByClassName('sydney-offcanvas-menu')[0]; closeButtonClone.addEventListener( 'click', function(e) { e.preventDefault(); closeButtonClone.focus(); closeButtonClone.classList.remove( 'open' ); offCanvas.classList.remove( 'toggled' ); document.body.classList.remove( 'mobile-menu-visible' ); } ); },1000); });
I cannot explain why, but now it doesn’t scroll up when closing the menu. Maybe this helps you somehow.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Close button of off-canvas menu scrolls to top’ is closed to new replies.