ハンバーガーメニュー:グラデーション|Hamburger Menu: Gradient

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="#">メニュー1</a>
        <a href="#">メニュー2</a>
        <a href="#">メニュー3</a>
    </nav>
</div>
CSS
@keyframes fadeIn {
    0% {
        top: 45%;
        opacity: 0;
    }
    
    100% {
        top: 50%;
        opacity: 1;
    }
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    25% { background-position: 100% 50%; }
    50% { background-position: 100% 100%; }
    75% { background-position: 0% 100%; }
    100% { background-position: 0% 50%; }
}

.container {
    position: relative;
    width: 100%;
    height: 300px;
}

.hamburger-menu {
    width: 42px;
    height: 32px;
    position: absolute;
    top: 20px;
    right: 20px;
    cursor: pointer;
    user-select: none;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57, #ff9ff3);
    background-size: 600% 600%;
    border-radius: 50%;
    padding: 10px;
    animation: gradientShift 4s ease infinite;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

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

.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);
    background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
}

.hamburger-menu.active > .line:nth-of-type(2) {
    opacity: 0;
    transform: scale(0) rotate(180deg);
}

.hamburger-menu.active > .line:nth-of-type(3) {
    bottom: 50%;
    transform: translateY(50%) rotate(-45deg);
    background: linear-gradient(90deg, #45b7d1, #96ceb4);
}

.nav-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    align-items: center;
    justify-content: center;
    padding: 25px;
    width: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    border-radius: 25px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    opacity: 0;
    border: 2px solid rgba(255,255,255,0.2);
}

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

.nav-menu a {
    text-decoration: none;
    color: white;
    padding: 10px;
    margin: 10px;
    border-radius: 25px;
    transition: all 0.4s;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255,255,255,0.2);
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.nav-menu a:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.4);
}
JavaScript
document.querySelector('.hamburger-menu').addEventListener('click', function() {
    this.classList.toggle('active');
    document.querySelector('.nav-menu').classList.toggle('active');
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次