After multiple attempts to create a hamburger menu, I have hit a roadblock. Clicking on the menu icon transforms it into an 'X', but unfortunately, it does not trigger the opening of the menu. Despite days of effort and research, I have yet to find a solution that actually works.
Below is the HTML code for the navmenu and hamburger icon:
let menu = document.querySelector('#menu-icon');
let navmenu = document.querySelector('.navmenu');
menu.onclick = () => {
menu.classList.toggle('bx-x');
navmenu.classList.toggle('open');
}
.navmenu {
display: flex;
}
.navmenu a {
color: #000;
font-size: 16px;
text-transform: capitalize;
padding: 10px 20px;
font-weight: 400;
transition: all .42s ease;
}
.navmenu a:hover {
color: #03A9F4;
}
.nav-icon {
display: flex;
align-items: center;
}
.nav-icon i {
margin-right: 20px;
color: #ffffff;
font-size: 25px;
font-weight: 400;
transition: all .42s ease;
}
.nav-icon i:hover {
transform: scale(1.1);
color: #03A9F4;
}
#menu-icon {
font-size: 35px;
display: none;
color: #ffffff;
z-index: 10001;
cursor: pointer;
}
@media(max-width: 750px) {
#menu-icon {
display: block;
}
.navmenu {
position: absolute;
top: -100%;
right: 0%;
width: 300px;
height: 130vh;
background: #000;
display: flex;
flex-direction: column;
align-items: center;
padding: 120px 30px;
transition: all .42s;
}
.navmenu a {
display: block;
margin: 10px 0;
}
.navmenu.open {
right: 0%
}
}
<a href="#" class="logo"><img src="images/logo5.png" alt="" class="prevent-select"></a>
<ul class="navmenu">
<li><a href="#" id="prevent-select" class="hover-underline-animation">Home</a></li>
<li><a href="#" id="prevent-select" class="hover-underline-animation">Shop</a></li>
<li><a href="#" class="hover-underline-animation" id="prevent-select">Sale</a></li>
<li><a href="#" class="hover-underline-animation" id="prevent-select">Contact</a></li>
<li><a href="#" class="hover-underline-animation" id="prevent-select">Policies</a></li>
<li><a href="#" class="hover-underline-animation" id="prevent-select">More</a></li>
</ul>
<div class="nav-icon">
<a href="#" id="prevent-select"><i class='bx bx-search-alt-2'></i></a>
<div class="dropdown2">
<button class="dropbtn2">
<a href="#" id="prevent-select"><i class='bx bx-user'></i></a>
</button>
<div class="dropdown-content2">
<div class="login">
<ul>
<a href="login_register.php" id="prevent-select">Log in/Register</a>
</ul>
</div>
</div>
</div>
<a href="#" id="prevent-select"><i class='bx bx-shopping-bag'></i></a>
<div class="bx bx-menu" id="menu-icon"></div>
</div>
Although I attempted the provided approach, it did not yield the intended result. My goal is to achieve a sliding effect to open the menu upon clicking the hamburger menu icon.