HTML
.container
.menu-icon
.menu-icon
<span>
<div class="container">
<div class="menu-icon">
<span></span>
<span></span>
<span></span>
</div>
</div>
CSS
Обертка
:root {
background-color: #333;
}
.container {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
Значок меню
<span>
.menu-icon
.menu-icon {
display: grid;
place-items: center;
height: 55px;
width: 55px;
cursor: pointer;
}
Диапазон
<span>
.menu-icon > span {
width: 50px;
height: 3px;
display: block;
background-color: red;
transition: all 0.3s ease-in-out;
margin: 5px 0;
}
.menu-icon > span:nth-child(1) {
width: 42px;
}
.menu-icon > span:nth-child(2) {
width: 35px;
}
Hover-эффект
.menu-icon:hover > span:nth-child(1) {
width: 30px;
}
.menu-icon:hover > span:nth-child(2) {
width: 40px;
}
Анимация при нажатии
.menu-icon.active span:nth-child(1) {
transform-origin: center center;
transform: rotate(-45deg) translate(-20%, 500%);
width: 55px;
}
.menu-icon.active span:nth-child(2) {
opacity: 0;
}
.menu-icon.active span:nth-child(3) {
transform-origin: center center;
transform: rotate(45deg) translate(-20%, -500%);
width: 55px;
}
JavaScript
.active
const menuIcon = document.querySelector('.menu-icon');
function toggleMenuIcon() {
menuIcon.classList.toggle('active');
}
menuIcon.addEventListener('click', toggleMenuIcon);
.active