ハンバーガーメニュー:パステルカラー(オーバーレイ)|Hamburger Menu: Pastel Colors Overlay

HTML
<div class="container">
    <div class="hamburger-menu">
        <div class="line"></div>
        <div class="line"></div>
        <div class="line"></div>
    </div>
    <div class="overlay"></div>
    <nav class="nav-menu">
        <a href="#">Menu 1</a>
        <a href="#">Menu 2</a>
        <a href="#">Menu 3</a>
        <a href="#">Menu 4</a>
        <a href="#">Menu 5</a>
        <a href="#">Menu 6</a>
        <a href="#">Menu 7</a>
        <a href="#">Menu 8</a>
        <a href="#">Menu 9</a>
        <a href="#">Menu 10</a>
    </nav>
</div>
CSS
.container {
    position: relative;
    width: 100%;
    height: 300px;
    background: #f8f9fa;
    margin: 20px 0;
}

.hamburger-menu {
    width: 40px;
    height: 30px;
    position: absolute;
    top: 20px;
    right: 20px;
    cursor: pointer;
    user-select: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    padding: 10px;
    box-shadow: 
        0 8px 32px rgba(0,0,0,0.1),
        0 4px 16px rgba(0,0,0,0.05);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.3);
    z-index: 1001;
}

.hamburger-menu:hover {
    transform: scale(1.05) rotate(5deg);
    box-shadow: 
        0 12px 40px rgba(0,0,0,0.15),
        0 6px 20px rgba(0,0,0,0.1);
}

.line {
    background: linear-gradient(90deg, #fd79a8, #a29bfe);
    height: 3px;
    width: calc(100% - 20px);
    position: absolute;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border-radius: 3px;
    left: 10px;
    box-shadow: 0 2px 8px rgba(253, 121, 168, 0.3);
}

.line:nth-of-type(1) {
    top: 25%;
}

.line:nth-of-type(2) {
    top: 50%;
    transform: translateY(-50%);
}

.line:nth-of-type(3) {
    bottom: 25%;
}

.hamburger-menu.active > .line:nth-of-type(1) {
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    background: linear-gradient(90deg, #ff7675, #fd79a8);
    box-shadow: 0 3px 12px rgba(255, 118, 117, 0.4);
}

.hamburger-menu.active > .line:nth-of-type(2) {
    opacity: 0;
    transform: translateX(-30px) scale(0.5);
}

.hamburger-menu.active > .line:nth-of-type(3) {
    bottom: 50%;
    transform: translateY(50%) rotate(-45deg);
    background: linear-gradient(90deg, #a29bfe, #74b9ff);
    box-shadow: 0 3px 12px rgba(162, 155, 254, 0.4);
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease;
    z-index: 999;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

.nav-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    align-items: center;
    justify-content: flex-start;
    padding: 20px 8px;
    width: 350px;
    background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 25%, #fd79a8 50%, #a29bfe 75%, #74b9ff 100%);
    border-radius: 30px;
    box-shadow: 
        0 20px 40px rgba(0,0,0,0.1),
        0 10px 20px rgba(0,0,0,0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.3);
    opacity: 0;
    z-index: 1000;
    max-height: 70%;
    overflow-y: auto;
}

.nav-menu.active {
    display: flex;
    animation: fadeIn 0.7s forwards;
}

.nav-menu a {
    text-decoration: none;
    color: white;
    padding: 20px;
    margin: 8px;
    border-radius: 25px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-weight: 500;
    position: relative;
    overflow: hidden;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
}

.nav-menu a::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s;
}

.nav-menu a.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.nav-menu a:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.5);
}

.nav-menu a:hover::before {
    left: 100%;
}

@keyframes fadeIn {
    0% {
        top: 45%;
        opacity: 0;
    }
    100% {
        top: 50%;
        opacity: 1;
    }
}
JavaScript
document.querySelector('.hamburger-menu').addEventListener('click', function() {
    const hamburgerMenu = this;
    const navMenu = hamburgerMenu.parentElement.querySelector('.nav-menu');
    const overlay = hamburgerMenu.parentElement.querySelector('.overlay');

    hamburgerMenu.classList.toggle('active');
    navMenu.classList.toggle('active');

    if (navMenu.classList.contains('active')) {
        // オーバーレイを表示
        overlay.classList.add('active');

        // オーバーレイアニメーション後にメニューを順番に表示
        setTimeout(() => {
            const menuItems = navMenu.querySelectorAll('a');
            menuItems.forEach((item, index) => {
                setTimeout(() => {
                    item.classList.add('show');
                }, index * 150); // 各メニューアイテムを150ms間隔で表示
            });
        }, 300); // オーバーレイアニメーション完了後
    } else {
        // メニューを非表示
        const menuItems = navMenu.querySelectorAll('a');
        menuItems.forEach(item => {
            item.classList.remove('show');
        });

        // メニュー非表示後にオーバーレイを非表示
        setTimeout(() => {
            overlay.classList.remove('active');
        }, 200);
    }
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!