I've been experimenting with a mobile-friendly navigation menu, and I'm facing an issue where the menu opens (JS IF statement) but doesn't close (JS ELSE statement). I'm unsure why it's opening but not closing.
P.S. I'm new to JavaScript, so it could be something simple that I have overlooked. Thank you!
Here is the code snippet I am currently working on:
function myFunction(x) {
x.classList.toggle("change");
}
function navChange() {
var x = document.getElementById("myNav").style.height;
if (x === "0%") {
document.getElementById("myNav").style.height = "100%";
} else {
document.getElementById("myNav").style.height = "0%";
}
}
.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-y: hidden;
transition: 0.5s;
}
/* CSS Styles Here */
If you have any insights or suggestions, please share them. Your time and help are greatly appreciated!