For the love of god! I have spent hours trying to figure this out, and nothing seems to work. Please, much help is needed.
So i have managed to write a menu burger (and i dont know how, it's the only component i managed to assign animations too). And on clicking on the burger menu some other links appear and i want it to ease-in/slide-in when appearing on click and out when disappearing on click. Same goes with the searchbar that appears on clicking the 'DISCOVER' link. I surrender!!
const menuBtn = document.querySelector('.menu-btn');
const menu = document.querySelector('.menu');
let menuOpen = false;
menuBtn.addEventListener('click', () => {
if (!menuOpen) {
menuBtn.classList.add('open');
menu.classList.add('open');
menuOpen = true;
} else {
menuBtn.classList.remove('open');
menu.classList.remove('open');
menuOpen = false;
}
});
const discoverLink = document.querySelector('.menuItem:first-child');
const searchbar = document.querySelector('.searchbar');
let searchOpen = false;
discoverLink.addEventListener('click', () => {
if (!searchOpen) {
searchbar.classList.toggle('open');
searchbar.classList.add('open');
searchOpen = true;
} else {
searchbar.classList.remove('open');
searchOpen = false;
}
});
@font-face {
font-family: 'Montserrat-Light';
src: url(fonts\Montserrat-Light.ttf) format(ttf);
}
body {
background: #272727;
display: flex;
justify-content: center;
align-items: center;
min-height: 10vh;
}
ul {
list-style: none;
}
.menu-btn {
position: absolute;
left: 20px;
display: flex;
justify-content: center;
align-items: center;
width: 40px;
height: 40px;
cursor: pointer;
transition: all .5s ease-in-out;
/* border: 3px solid #fff; */
}
.menu-btn__burger {
width: 30px;
height: 4px;
background: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(255, 101, 47, .2);
transition: all .5s ease-in-out;
}
.menu-btn__burger::before,
.menu-btn__burger::after {
content: '';
position: absolute;
width: 30px;
height: 4px;
background: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(255, 101, 47, .2);
transition: all .5s ease-in-out;
}
/*desloca 1 faixa para cima e outra para baixo */
.menu-btn__burger::before {
transform: translateY(-6px);
}
.menu-btn__burger::after {
transform: translateY(6px);
}
/* ANIMATION */
.menu-btn.open .menu-btn__burger {
transform: translateX(-32px);
background: transparent;
box-shadow: none;
}
.menu-btn.open .menu-btn__burger::before {
transform: rotate(45deg) translate(35px, -35px);
}
.menu-btn.open .menu-btn__burger::after {
transform: rotate(-45deg) translate(35px, 35px);
}
.menu {
display: none;
/* hide the menu by default */
}
.menu-btn.open+.menu {
display: inline-block;
/* display the menu when the button is clicked */
}
.menu-links {
position: relative;
left: 100px;
top: 3px;
}
.menu-links a {
text-decoration: none;
/* remove the underline */
font: 12px Montserrat-Light, sans-serif;
color: lightgray;
}
.menu__item {
display: inline-block;
margin-right: 10px;
}
.navShowed {
position: absolute;
display: flex;
width: 280px;
right: 10px;
margin-top: auto;
}
.menuItem {
font: 12px Montserrat-Light, sans-serif;
display: inline-block;
margin-right: 20px;
cursor: pointer;
color: lightgray;
}
.discover-link {
position: relative;
}
.searchbar {
display: none;
position: relative;
right: 300px;
top: 38%;
width: 200px;
height: 15px;
transform: translateY(-50%);
transition: all 0.5s ease-in-out;
}
.searchbar input[type="text"] {
width: 100%;
height: 100%;
padding: 0 20px;
font-size: 10px;
color: #333;
}
.searchbar.open {
display: inline-block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Trying Animations out</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="menu-btn">
<div class="menu-btn__burger"></div>
</div>
<ul class="menu">
<div class="menu-links">
<li class="menu__item"><a href="#about">NIKE</a></li>
<li class="menu__item"><a href="#services">NEW BALLANCE</a></li>
<li class="menu__item"><a href="#contact">REEBOK</a></li>
<li class="menu__item"><a href="#contact">ADIDAS</a></li>
<li class="menu__item"><a href="#contact">ASICS</a></li>
</div>
</ul>
<div class="navShowed">
<h3 class="menuItem discover-link">DISCOVER</h3>
</div>
<div class="searchbar">
<input type="text" placeholder="Search...">
</div>
<script src="main.js"></script>
</body>
</html>