비전공자 개발일기

HAMBURGER ANIMATION 본문

Javascript

HAMBURGER ANIMATION

HiroDaegu 2022. 4. 18. 01:10
728x90
SMALL

평소의 메뉴바
클릭시 변형 형태

<button type="button" class="hamburger">
  <span class="line"></span>
  <span class="line"></span>
  <span class="line"></span>
</button>
.hamburger {
  background-color: transparent;
  border: none;
  outline: none;
  cursor: pointer;
}

.hamburger .line {
  display: block;
  width: 40px;
  height: 3px;
  background-color: #6667ab;
  margin-block: 10px;
  border-radius: 4px;
  transition: transform .5s, 
    opacity: .25s;
}

.hamburger.active .line:nth-child(1) {
  transform: translateY(13px) 
    rotate(45deg);
}

.hamburger.active .line:nth-child(2) {
  opacity: 0;
}

.hamburger.active .line:nth-child(3) {
  transform: translateY(-13px) 
    rotate(-45deg);
}
const hamburger = document.querySelector(".hamburger");
const menuIsActive = () => {
  hamburger.classList.toggle('active');
}
hamburger.addEventListener('click', menuIsActive);

 

728x90
LIST

'Javascript' 카테고리의 다른 글

Circle Loading Tape  (0) 2022.04.24
Age Calculator  (0) 2022.04.21
[HTML & Javascript] radio 버튼으로 테이블 항목 바꾸기  (0) 2022.01.12
swal() - 예쁜 알림창  (0) 2021.12.17
Javascript - Update CSS  (0) 2021.11.04