モーダルウィンドウ:ダーク(フルスクリーン)|Modal Window: Minimal Fullscreen

HTML
<div class="container">
    <button id="modal-btn" class="modal-button">Dark Fullscreen Modal</button>
</div>

<div id="mask" class="mask"></div>
<div id="modal" class="modal">
    <div class="modal-content">
        <div class="close-btn-container">
            <button class="close-btn">×</button>
        </div>
        <div class="fullscreen-content">
            <p>[Dark Fullscreen Modal]</p>
            <p>A dark-themed fullscreen modal window. Easy on the eyes and perfect for nighttime use or dark-themed applications.</p>
            <p>Features a sleek dark design with subtle animations and modern typography for an elegant user experience.</p>
            <p>You can also close with the ESC key.</p>
            <div class="close-btn-container">
                <button class="close-btn">CLOSE</button>
            </div>
        </div>
    </div>
</div>
CSS
.container {
    text-align: center;
}

.modal-button {
    padding: 15px 30px;
    background: #212529;
    color: #ffffff;
    border: 2px solid #495057;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.modal-button:hover {
    background: #343a40;
    border-color: #6c757d;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.close-btn-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
}

.close-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.fullscreen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 40px;
    text-align: center;
}

.fullscreen-content p {
    color: #adb5bd;
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 20px;
    max-width: 600px;
}

.fullscreen-content .close-btn-container {
    position: static;
    margin-top: 30px;
}

.fullscreen-content .close-btn {
    padding: 12px 30px;
    background: #ffffff;
    color: #1a1a1a;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
    width: auto;
    height: auto;
    line-height: 1.2;
    white-space: nowrap;
    min-width: 120px;
}

.fullscreen-content .close-btn:hover {
    background: #f8f9fa;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
    .fullscreen-content {
        padding: 40px 20px;
    }
    
    .fullscreen-content p {
        font-size: 1rem;
    }
}
JavaScript
document.addEventListener('DOMContentLoaded', function() {
    const modalBtn = document.getElementById('modal-btn');
    const mask = document.getElementById('mask');
    const modal = document.getElementById('modal');
    const closeBtns = document.querySelectorAll('.close-btn');

    // モーダルを開く
    modalBtn.addEventListener('click', () => {
        mask.classList.add('appear');
        modal.classList.add('appear');
        document.body.style.overflow = 'hidden';
    });

    // モーダルを閉じる関数
    const closeModal = () => {
        mask.classList.remove('appear');
        modal.classList.remove('appear');
        document.body.style.overflow = 'auto';
    };

    // マスククリックで閉じる
    mask.addEventListener('click', closeModal);

    // 閉じるボタンで閉じる
    closeBtns.forEach(btn => {
        btn.addEventListener('click', closeModal);
    });

    // ESCキーで閉じる
    document.addEventListener('keydown', function(e) {
        if (e.key === 'Escape' && modal.classList.contains('appear')) {
            closeModal();
        }
    });
});
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!