モーダルウィンドウ:3D立体|Modal Window: Three-Dimension

HTML
<div class="container">
    <button class="modal-button">3D Modal</button>
    <div class="mask"></div>
    <div class="modal">
        <div class="modal-content">
            <p>【3D Modal】</p>
            <p>A three-dimensional modal window with perspective effects. Creates depth and visual interest with 3D transformations.</p>
            <div class="close-btn-container">
                <button class="close-btn">Close</button>
            </div>
        </div>
    </div>
</div>
CSS
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    padding: 20px;
    margin: 0;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
    color: #fff;
}

.modal-button {
    padding: 15px 30px;
    background: linear-gradient(145deg, #ffffff, #e6e6e6);
    color: #333;
    border: none;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 
        0 8px 16px rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transform-style: preserve-3d;
    position: relative;
}

.modal-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(145deg, #f0f0f0, #ffffff);
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.modal-button:hover {
    transform: perspective(1000px) rotateX(-2deg) translateY(-2px);
    box-shadow: 
        0 15px 30px rgba(0, 0, 0, 0.15),
        0 8px 16px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    color: #2196f3;
}

.modal-button:active {
    transform: perspective(1000px) rotateX(3deg) translateY(1px);
    box-shadow: 
        0 4px 8px rgba(0, 0, 0, 0.1),
        0 2px 4px rgba(0, 0, 0, 0.06),
        inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s ease;
    backdrop-filter: blur(12px);
    pointer-events: auto;
}

.mask.appear {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.7) rotateX(-15deg) rotateY(-5deg);
    background: linear-gradient(145deg, #f8f9fa, #ffffff);
    padding: 40px;
    border-radius: 20px;
    z-index: 1002;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 500px;
    width: 90%;
    box-shadow: 
        0 25px 50px rgba(0, 0, 0, 0.3),
        0 15px 30px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transform-style: preserve-3d;
    perspective: 1000px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    pointer-events: auto;
}

.modal.appear {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1) rotateX(0deg) rotateY(0deg);
}

.modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.1), transparent);
}

.modal p {
    color: #555;
    line-height: 1.7;
    margin-bottom: 30px;
    font-size: 16px;
    font-weight: 500;
}

.close-btn {
    padding: 12px 24px;
    background: linear-gradient(145deg, #2196f3, #1976d2);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 
        0 4px 8px rgba(33, 150, 243, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform-style: preserve-3d;
    position: relative;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.close-btn:hover {
    background: linear-gradient(145deg, #1976d2, #1565c0);
    box-shadow: 
        0 6px 12px rgba(33, 150, 243, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.close-btn:active {
    box-shadow: 
        0 2px 4px rgba(33, 150, 243, 0.3),
        inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .modal {
        width: 95%;
        padding: 20px;
    }
    
    .modal p {
        font-size: 14px;
    }
    
    .modal-button {
        font-size: 14px;
        padding: 10px 20px;
    }
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
    const modalBtn = document.querySelector('.modal-button');
    const mask = document.querySelector('.mask');
    const modal = document.querySelector('.modal');
    const closeBtn = document.querySelector('.close-btn');
    
    // モーダルを開く
    modalBtn.addEventListener('click', () => {
        mask.classList.add('appear');
        modal.classList.add('appear');
    });
    
    // マスクをクリックして閉じる
    mask.addEventListener('click', () => {
        mask.classList.remove('appear');
        modal.classList.remove('appear');
    });
    
    // 閉じるボタンをクリックして閉じる
    closeBtn.addEventListener('click', () => {
        mask.classList.remove('appear');
        modal.classList.remove('appear');
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!
目次