I'm making a simple menu with css and jquery. It works great but when I open it I can't click the elements below.
https://jsfiddle.net/tano4xv1/
<header>
<nav>
<span>
<img src="img/header.png" alt="logo">
<i class="fas fa-bars trigger">menu</i>
</span>
<span class="menu-container hidden">
<div class="menu">
<a href="#">option</a>
<a href="#">option</a>
<a href="#">option</a>
<a href="#">option</a>
</div>
</span>
</nav>
<p><a href="#">Option I can't click</a></p>
<p><a href="#">Option I can't click</a></p>
<p><a href="#">Option I can't click</a></p>
<p><a href="#">Option I can't click</a></p>
JQUERY is basically a class toggle to move between the div positions
const menu = document.querySelector('.menu');
const trigger = document.querySelector('.trigger');
function toggle() {
menu.classList.toggle('menu--open');
}
trigger.addEventListener('click', toggle);
My css. The animation was made with pure CSS. I'm moving the div when click the menu button.
.menu {
position: relative;
top: -300px;
transition: 0.3s all;
}
.menu--open {
top: 0;
transition: 0.3s all;
}
nav {
width: 100%;
height: 70px;
position: absolute;
z-index: 1;
top: 0;
}
nav span {
display: flex;
align-items: center;
justify-content: space-between;
}
nav span:nth-child(1) {
background: white;
z-index: 1;
position: relative;
}
.menu-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.fa-bars {
margin-right: 20px;
font-size: 20px;
}
.fa-bars:hover {
cursor: pointer;
}
span .menu {
background: #95baa8;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
span .menu a {
padding: 15px;
text-decoration: none;
color: white;
}