ハンバーガーメニュー:3D立体|Hamburger Menu: Three-Dimension

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;
    }
}

.container {
    position: relative;
    width: 100%;
    height: 400px;
    border-radius: 20px;
    margin: 20px 0;
}

.hamburger-menu {
    width: 45px;
    height: 35px;
    position: absolute;
    top: 20px;
    right: 20px;
    cursor: pointer;
    user-select: none;
    background: linear-gradient(145deg, #e6e6e6, #ffffff);
    border-radius: 15px;
    padding: 12px;
    box-shadow: 
        5px 5px 10px #d1d1d1,
        -5px -5px 10px #ffffff,
        0 4px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.hamburger-menu:hover {
    transform: translateY(-2px);
    box-shadow: 
        6px 6px 12px #d1d1d1,
        -6px -6px 12px #ffffff,
        0 6px 12px rgba(0,0,0,0.15);
}

.hamburger-menu:active {
    transform: translateY(0);
    box-shadow: 
        inset 3px 3px 6px #d1d1d1,
        inset -3px -3px 6px #ffffff;
}

.line {
    background: linear-gradient(90deg, #666, #999);
    height: 4px;
    width: calc(100% - 24px);
    position: absolute;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 2px;
    left: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.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, #ff8e8e);
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.4);
}

.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, #4ecdc4, #6ee7df);
    box-shadow: 0 2px 6px rgba(78, 205, 196, 0.4);
}

.nav-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    align-items: center;
    justify-content: center;
    padding: 30px;
    width: 50%;
    background: linear-gradient(145deg, #e6e6e6, #ffffff);
    border-radius: 25px;
    box-shadow: 
        8px 8px 16px #d1d1d1,
        -8px -8px 16px #ffffff,
        0 15px 30px rgba(0,0,0,0.2);
    opacity: 0;
    border: 1px solid rgba(255,255,255,0.8);
}

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

.nav-menu a {
    text-decoration: none;
    color: #555;
    padding: 15px 25px;
    margin: 10px;
    border-radius: 20px;
    transition: all 0.3s ease;
    background: linear-gradient(145deg, #f0f0f0, #ffffff);
    box-shadow: 
        3px 3px 6px #d1d1d1,
        -3px -3px 6px #ffffff;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.8);
}

.nav-menu a:hover {
    background: linear-gradient(145deg, #e0e0e0, #f0f0f0);
    transform: translateY(-3px);
    box-shadow: 
        4px 4px 8px #d1d1d1,
        -4px -4px 8px #ffffff,
        0 8px 16px rgba(0,0,0,0.1);
    color: #333;
}

.nav-menu a:active {
    transform: translateY(-1px);
    box-shadow: 
        inset 2px 2px 4px #d1d1d1,
        inset -2px -2px 4px #ffffff;
}
JavaScript
const hamburgerMenu = document.querySelector('.hamburger-menu');
const navMenu = document.querySelector('.nav-menu');

hamburgerMenu.addEventListener('click', function() {
    hamburgerMenu.classList.toggle('active');
    navMenu.classList.toggle('active');
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次