Project Tracking Main, first Mobile using React with Vite
Design comparison
Solution retrospective
Hi guys, this is my solution using React for the first time but i have 2 problems, in the mobile design, i try to add a element.classlist.toggle for show the mobile menu, but when i do this i have a error, and second, i cant move the background in the image, if any one can help me i really appreciate this, thankyou, happy coding!
Community feedback
- @thulanigamteePosted almost 2 years ago
To fix the functionality for the mobile menu, remove;
const mobileContainer = document.querySelector(".mobileContainer") const [visible, setVisible] = useState(false) const mostrar = () =>{ if(visible == false){ mobileContainer.style.visibility = "visible" setVisible(visible = true) }else{ mobileContainer.style.visibility = "hidden" setVisible(visible = false) } }
I don't think you need that, replace it with this;
const mostrar = () => { document.querySelector(".mobileContainer").classList.toggle("active"); }
Then on your css, I removed visibility, and used
display:none
, then toggled it, like this;.mobileContainer { display: none; } .mobileContainer.active { display: flex; flex-direction: column; justify-content: space-evenly; align-items: center; min-height: 40vh; width: 80%; margin-left: 10%; position: fixed; background-color: white; box-shadow: 0 0 20px -5px black; border-radius: 5px; }
That seemed to do the trick, and I am not sure what mostrar is, when naming your functions or anything for that matter try using descriptive words, rather than mostrar, something like
toggleMobileMenu
for the function would have been way better, because that is what it does, it toggles the mobile menu.Marked as helpful0@DiegoPasayePosted almost 2 years ago@thulanigamtee Thank you, i can fix this with your solution, i put the class mostrar because i speak spanish and it is show in english, but is an error, im trying to name the variables in english, thanks!
1
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