I've been following an online tutorial to spice up my navigation bars a bit, but I'm having trouble getting my burger menu and animations to work.
I've included the JS file above </body>
(I also tried moving it into the <head>
).
Could it be related to how it's saved, or did I make a really obvious mistake?
const navSlide = () => {
const burger = document.querySelector('.burger');
const nav = document.querySelector('.nav-links');
const navLinks = document.querySelectorAll('.nav-links li');
//Toggle Nav //
burger.addEventListener('click', () => {
nav.classList.toggle('nav-active');
});
}
navSlide();
.nav-links {
display: flex;
justify-content: space-around;
width: 40%;
}
.nav-links a {
text-decoration: none;
color: white;
font-weight: bold;
font-size: 14px;
}
.nav-links li {
list-style: none;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
}
@media screen and (max-width:768px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: #006a71;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
transition: 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%) !important;
}
<ul class="nav-links">
<li><a href="#">Home</a></li>
<li><a href="#">Projects</a></li>
<li><a href="#">Gallery</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>