I’m using the Dawn theme because I want the mobile header to be sticky. When I open the mobile hamburger menu, the page scrolls to the bottom. Can someone help me fix this?
Website: https://ambersilverz.myshopify.com/
Password: amber
A user is experiencing an issue with the Dawn theme where opening the mobile hamburger menu causes the page to scroll to the bottom, despite wanting a sticky header.
Proposed Solution:
A community member suggested overriding the menu drawer’s CSS and JavaScript behavior by:
theme.css or base.css to fix the menu drawer position and prevent scroll jumpstheme.liquid before the closing </body> tag or in assets/header-drawer.js) to lock scroll behaviorImplementation Details:
The helper provided two placement options for the JavaScript snippet with step-by-step instructions for accessing the theme code editor.
Current Status:
The issue remains unresolved — the original poster reported that the suggested fix did not work and has requested additional help. No further solutions have been provided yet.
I’m using the Dawn theme because I want the mobile header to be sticky. When I open the mobile hamburger menu, the page scrolls to the bottom. Can someone help me fix this?
Website: https://ambersilverz.myshopify.com/
Password: amber
You can fix this by overriding the menu drawer CSS and JS behavior. Try adding this snippet in your theme.css (or base.css):
/* Prevent page scroll jump when opening mobile menu */
.menu-drawer {
position: fixed;
top: 0;
left: 0;
height: 100vh;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
And in theme.liquid or header-drawer.js, ensure scroll locking doesn’t force a jump. Add:
document.addEventListener('DOMContentLoaded', function() {
const menuDrawer = document.querySelector('.menu-drawer')
if (menuDrawer) {
menuDrawer.addEventListener('transitionend', () => {
window.scrollTo(0,0)
})
}
})
@Fayyaz_Ahmed where to place the below js code, under which tag
Hi Sivadarshan,
Good question. You can add that JS snippet in one of two safe places:
theme.liquidGo to Online Store > Themes > Edit code
Open layout/theme.liquid
Scroll to the bottom, just before the closing </body> tag
Paste the script:
<script>
document.addEventListener('DOMContentLoaded', function() {
const menuDrawer = document.querySelector('.menu-drawer')
if (menuDrawer) {
menuDrawer.addEventListener('transitionend', () => {
window.scrollTo(0,0)
})
}
})
</script>
header-drawer.jsIf you prefer to keep everything in JS files, open assets/header-drawer.js
Paste the code at the bottom of that file.
Save and publish.
Sorry it’s not working, can you please help with me