ハンバーガーメニュー:ボーダー(カスケード)|Hamburger Menu: Border Cascade
HTML
<div class="container">
<div class="hamburger-menu">
<div class="line"></div>
<div class="line"></div>
<div class="line"></div>
</div>
<nav class="nav-menu">
<a href="#">Menu 1</a>
<a href="#">Menu 2</a>
<a href="#">Menu 3</a>
</nav>
</div>
CSS
.container {
position: relative;
width: 100%;
height: 300px;
border: 2px solid #333;
border-radius: 8px;
overflow: hidden;
background: white;
}
.hamburger-menu {
width: 32px;
height: 24px;
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
user-select: none;
border: 2px solid #333;
border-radius: 6px;
padding: 6px;
transition: all 0.3s;
}
.hamburger-menu:hover {
border-color: #666;
background: #f5f5f5;
}
.line {
background-color: #333;
height: 2px;
width: calc(100% - 12px);
position: absolute;
transition: all 0.3s ease;
left: 6px;
}
.line:nth-of-type(1) {
top: 20%;
}
.line:nth-of-type(2) {
top: 50%;
transform: translateY(-50%);
}
.line:nth-of-type(3) {
bottom: 20%;
}
.hamburger-menu.active > .line:nth-of-type(1) {
top: 50%;
transform: translateY(-50%) rotate(45deg);
}
.hamburger-menu.active > .line:nth-of-type(2) {
opacity: 0;
}
.hamburger-menu.active > .line:nth-of-type(3) {
bottom: 50%;
transform: translateY(50%) rotate(-45deg);
}
.nav-menu {
display: none;
flex-direction: column;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
align-items: flex-start;
justify-content: flex-start;
padding: 0;
width: 33%;
min-height: 120px;
max-height: 80%;
background: white;
border: 3px solid #333;
border-radius: 10px;
opacity: 0;
overflow: hidden;
}
.nav-menu.active {
display: flex;
animation: slideInFromTop 0.4s forwards;
}
@keyframes slideInFromTop {
0% {
top: -100px;
opacity: 0;
}
100% {
top: 50%;
opacity: 1;
}
}
.nav-menu a {
text-decoration: none;
color: #333;
padding: 15px 20px;
margin: 0;
width: 100%;
text-align: center;
border-bottom: 1px solid #ddd;
transition: all 0.3s;
opacity: 0;
transform: translateY(-20px);
pointer-events: none;
position: relative;
box-sizing: border-box;
}
.nav-menu a.show {
opacity: 1;
transform: translateY(0);
pointer-events: auto;
}
.nav-menu a:hover {
background: #f8f8f8;
color: #333;
padding-left: 25px;
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
const hamburgerMenu = document.querySelector('.hamburger-menu');
const navMenu = document.querySelector('.nav-menu');
hamburgerMenu.addEventListener('click', () => {
hamburgerMenu.classList.toggle('active');
navMenu.classList.toggle('active');
if (navMenu.classList.contains('active')) {
const menuItems = navMenu.querySelectorAll('a');
menuItems.forEach((item, index) => {
setTimeout(() => {
item.classList.add('show');
}, 250 + (index * 150));
});
} else {
const menuItems = navMenu.querySelectorAll('a');
menuItems.forEach(item => {
item.classList.remove('show');
});
}
});
});