I think I have a jQuery problem.
So when I'm using the PC version of my website and I click in navbar items (which is #menu-two .items
in my HTML code), the navbar menu disappears.
I have some media queries to readjust the navbar menu and in this media queries I want the navbar (which is .hide) to hide when I click on the navbar items, in this case tablet and mobile version.
It seems that the computer version cannot be separated from these two versions in this case and hides the #menu-two
too.
$('.toggle').on('click', function() {
$('.toggle').toggleClass('active');
$('#menu-two').toggleClass('hide')
$('.hide').fadeToggle()
})
$('.active').on('click', function() {
$('.toggle').fadeToggle()
})
$('.item').on('click', function() {
$('.hide').fadeToggle()
})
.toggle {
display: none;
}
a {
text-decoration: none;
font-family: 'Open Sans Condensed', sans-serif;
letter-spacing: 1px;
font-size: 20px;
color: black
}
#menu-two {
display: flex;
}
.hide {
display: none;
}
li {
list-style: none;
padding: 1em
}
@media only screen and (max-width: 1210px) {
#menu-two {
display: none;
}
.hide {
background-color: rgb(253, 236, 214);
opacity: 0.95;
position: absolute;
width: 100%;
top: 4rem;
text-align: center;
}
.options {
display: block;
}
.menu-one {
display: flex;
justify-content: space-between;
width: 100%
}
.toggle {
display: initial;
padding-top: 1.5rem;
transform: translate(-10px);
cursor: pointer;
}
.toggle span {
position: relative;
width: 36px;
height: 4px;
display: block;
background-color: black;
margin-bottom: 8px;
transition: 0.5s;
}
.toggle span:nth-child(1) {
transform-origin: left;
}
.toggle span:nth-child(2) {
transform-origin: center;
}
.toggle span:nth-child(3) {
transform-origin: left;
}
.toggle.active span:nth-child(1) {
transform: rotate(45deg);
left: 2px;
}
.toggle.active span:nth-child(2) {
transform: rotate(315deg);
right: 3px;
}
.toggle.active span:nth-child(3) {
transform: scaleX(0);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="menu-one">
<div class="toggle">
<span></span>
<span></span>
<span></span>
</div>
</div>
<ul id="menu-two" class="hide">
<li class="item">
<a href="./prototype.html">Home</a>
</li>
<li class="item" id="proj">
<a href="./exp.html">Projects</a>
</li>
<li class="options">
<a href="./Atower.html">A-Tower</a>
</li>
<li class="options">
<a href="./muda.html">Muda</a>
</li>
<li class="item">
<a href="#About-Me">About</a>
</li>
<li class="item">
<a href="#Contact">Contact</a>
</li>
</ul>
The problem is when I use this jQuery code, it is acting not only in my media queries, but outside of it too, so my navbar is hidden in PC version even though a I had a display: none
in .hide
class.
What should I do?