Landing Pages with dropdown (css and js)
Design comparison
Solution retrospective
I have issues when pages is desktop and then go to mobile open menu and back to mobile my header dessapear, its just that mistake, i really apreciatte if you check this page please, have a nice day:)
Community feedback
- @elaineleungPosted over 2 years ago
Hi Eliezer, well done in trying to build this out. I just had a look at your code to see what's happening with the mobile nav. Firstly, I think a lot of things can be firstly simplified. Since you only got one
container_list
, you can usequerySelector
instead, sincegetElementsByClassName
has the ability to modify your DOM.In any case, I think the main issue is, your
showMobileMenu
function only gets called once when the page loads, which is the only time theeventListener
would be activated. The function doesn't get called again when the icon is clicked a second time. What you need to do is, you need to put theeventListener
at the top level (as in, not have it nested or put within any functions). I think I would try something like this:const iconMenu = document.querySelector(".menu_icon"); const menuDrop = document.querySelector(".container_list"); const main = document.querySelector("main"); iconMenu.addEventListener("click", function() { if (menuDrop.style.display == "flex") { menuDrop.style.display = "none"; main.style.backgroundColor = "rgba(0,0,0,0.0)" } else { menuDrop.style.display = "flex"; main.style.backgroundColor = "rgba(0,0,0,0.8)" } })
Let me know if that works, and if not, we'll try something else!
0
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