I am currently in the process of developing a test drop-down menu. The open menu button functions correctly, however, the close button is unresponsive to clicking or hovering actions. Upon clicking the open menu button, it should make the other button visible and clickable as well.
The issue with the close button seems to lie in its display
property being reset to block
upon click events.
function toggleMenu() {
var hamburger = document.getElementById("burg");
var crossIcon = document.getElementById("cross");
var freezeBody = document.getElementById("body_freeze");
var navList = document.getElementById("nav_list");
var navItems = document.getElementsByClassName("nav_item");
if (hamburger.style.display === 'none') {
hamburger.style.display = 'block';
crossIcon.style.display = 'none';
navList.style.display = 'none';
freezeBody.style.position = 'relative';
} else {
hamburger.style.display = 'none';
crossIcon.style.display = 'block';
navList.style.display = 'block';
freezeBody.style.position = 'fixed';
}
}
.fixed_nav {
position: fixed;
width: 100%;
top: 0;
left: 0;
height: 50px;
background-color: white;
border-bottom: 1px solid black;
box-shadow: 0 4px 8px 0 rgb(0, 0, 0, .2);
}
#burg {
z-index: 3;
float: right;
display: block;
margin: 20px;
width: 100px;
height: auto;
}
#burg:hover {
background-color: gray;
}
#cross {
z-index: 3;
margin: 20px;
display: none;
float: right;
width: 100px;
height: auto;
}
#cross:hover {
background-color: gray;
}
#nav_list {
height: 100vh;
width: 100%;
background-color: white;
display: none;
z-index: 1;
}
#dummy_text {
margin-top: 50px;
}
.nav_item {
margin-top: 50px;
color: red;
width: 100%;
background-color: white;
border-top: 1px solid black;
border-bottom: 1px solid black;
z-index: 2;
}
#body_freeze {}
<html>
<head>
<title>ExampleError</title>
</head>
<body>
<nav class="fixed_nav">
<button id="burg" onclick="toggleMenu();">
☰
</button>
<button id="cross" onclick="toggleMenu();">
˟
</button>
<ul id="nav_list">
<div class="nav_item">
<a href="#">
<li>Inventory</li>
</a>
</div>
<div class="nav_item">
<a href="#">
<li>Finance</li>
</a>
</div>
</ul>
</nav>
<div id="body_freeze">
<p id="dummy_text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...<!--Text continues-->
</p>
</div>
</body>
</html>