Design comparison
Solution retrospective
A little bit of JS to the hamburger menu
I didn't know how to remove the scroll when someone opens the navigation bar on mobile
Community feedback
- @amalkarimPosted almost 2 years ago
Hi Stiratto 👋
Congratulations for completing this challenge!
To remove the scroll when navigation bar is opened, we need to add some codes in JavaScript. We will make
body
unscrollable withoverflow-y: hidden;
when nav bar is opened, and revert it to scrollable state when nav bar is closed. Take a look at the edited code below.navbar.addEventListener("click", () => { document.getElementById("navBarUl").style.display = 'block'; document.body.style.overflowY = 'hidden'; }) navbarClose.addEventListener("click", () => { document.getElementById("navBarUl").style.display = 'none'; document.body.style.overflowY = 'auto';
That will solve the problem. But, I see another problem. When the mobile nav bar is opened, we can actually scroll left and right, because the nav bar has
width:100%;
. To avoid this, please change inposition: absolute;
toposition: fixed;
in#navBarUl
.Hope this helps. Happy coding!
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord