document.body.classList.add('js');
var toggle = document.querySelector('#toggle-navigation');
var menu = document.querySelector('#menu');
var menuItems = document.querySelectorAll('#menu li a');
toggle.addEventListener('click', function(){
if (menu.classList.contains('is-active')) {
this.setAttribute('aria-expanded', 'false');
menu.classList.remove('is-active');
} else {
menu.classList.add('is-active');
this.setAttribute('aria-expanded', 'true');
}
});
<nav>
<button id="toggle-navigation" aria-expanded="false">
<span class="icon-menu"></span><span class="hidden">Menu</span>
</button>
<ul id="menu">
<?php foreach ($navigation as $link) { ?>
<li>
<a href="category.php?id=<?= $link['id'] ?>"
<?= ($section == $link['id'] ) ? 'class="on" aria-current="page"' : '' ?>>
<?= html_escape($link['name']) ?>
</a>
</li>
<?php } ?>
</ul>
</nav>
토글햄버거메뉴
<a href="#" class="menu">
<span></span>
<span></span>
<span></span>
<span></span>
</a>
$('.menu').click(function(e){
e.preventDefault();
$(this).toggleClass('active');
})
.menu{display: block;position: relative; transition: 0.3s ease-in-out;width: 45px; height: 34px;}
.menu span{position: absolute; height: 8px; border-radius: 4px; width: 100%; background-color: #000; transition: all 0.2s; top: 0;}
.menu span:nth-child(1){top: 0;}
.menu span:nth-child(2), .menu span:nth-child(3){top:13px;}
.menu span:nth-child(4){top: 26px;}
.menu.active span{opacity: 0;}
.menu.active span:nth-child(2){opacity: 1; transform: rotate(45deg);}
.menu.active span:nth-child(3){opacity: 1; transform: rotate(-45deg);}
'Js' 카테고리의 다른 글
offset().top 메뉴 스크롤하기 (0) | 2024.06.29 |
---|---|
썸네일이 있는 갤러리 (0) | 2024.06.29 |
연속된 이미지들 스크롤이나 슬라이더로 조절하기 (0) | 2024.06.29 |
웹디자인기능사 실기 제이쿼리 부분 (0) | 2024.06.29 |
input radio 라디오버튼 값으로 특정 css 변경 (0) | 2024.05.13 |
팝업 popup (0) | 2024.05.05 |
시간차 parallax 패럴렉스 표현 (0) | 2024.04.28 |
goto top (0) | 2024.04.27 |