侧面滑动模态框

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>侧面滑动模态框</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: #f5f5f5;
            padding: 20px;
            transition: all 0.3s ease;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        h1 {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
        }
        
        .content {
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        p {
            margin-bottom: 15px;
        }
        
        .btn {
            display: inline-block;
            padding: 12px 24px;
            background: linear-gradient(to right, #3498db, #2c3e50);
            color: white;
            text-decoration: none;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
        }
        
        .btn-open-sidebar {
            position: fixed;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
            padding: 15px;
            background: linear-gradient(to right, #3498db, #2c3e50);
            color: white;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
            cursor: pointer;
            z-index: 900;
            box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
            transition: all 0.3s ease;
        }
        
        .btn-open-sidebar:hover {
            padding-left: 20px;
            box-shadow: 3px 0 8px rgba(0, 0, 0, 0.3);
        }
        
        .sidebar-modal {
            position: fixed;
            top: 0;
            right: -400px;
            width: 400px;
            height: 100%;
            background: white;
            z-index: 1000;
            box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
            transition: all 0.4s ease;
            overflow-y: auto;
        }
        
        .sidebar-modal.active  {
            right: 0;
        }
        
        .sidebar-header {
            padding: 20px;
            background: linear-gradient(to right, #3498db, #2c3e50);
            color: white;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .sidebar-title {
            font-size: 20px;
            font-weight: bold;
        }
        
        .btn-close-sidebar {
            background: none;
            border: none;
            color: white;
            font-size: 24px;
            cursor: pointer;
            transition: transform 0.3s;
        }
        
        .btn-close-sidebar:hover {
            transform: rotate(90deg);
        }
        
        .sidebar-content {
            padding: 20px;
        }
        
        .sidebar-footer {
            padding: 15px;
            background: #f5f5f5;
            text-align: center;
        }
        
        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 999;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }
        
        .overlay.active  {
            opacity: 1;
            visibility: visible;
        }
        
        .website-link {
            display: block;
            text-align: center;
            margin-top: 30px;
            color: #3498db;
            font-weight: bold;
            text-decoration: none;
            transition: color 0.3s;
        }
        
        .website-link:hover {
            color: #2c3e50;
            text-decoration: underline;
        }
        
        @media (max-width: 768px) {
            .sidebar-modal {
                width: 320px;
                right: -320px;
            }
            
            .btn-open-sidebar {
                padding: 12px;
                font-size: 14px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>网页侧面滑动模态框演示</h1>
        
        <div class="content">
            <p>这是一个演示侧面滑动模态框的网页模板。点击左侧的按钮可以滑出一个侧边栏模态框。</p>
            <p>侧边栏模态框是一种常见的UI设计模式,适合用于显示导航菜单、设置面板、购物车等内容。</p>
            <p>这个实现使用了纯CSS过渡效果和简单的JavaScript来控制显示/隐藏。</p>
            

        </div>
    </div>
    
    <button class="btn-open-sidebar" id="openSidebar">≡ 打开侧边栏</button>
    
    <div class="sidebar-modal" id="sidebarModal">
        <div class="sidebar-header">
            <div class="sidebar-title">侧边栏标题</div>
            <button class="btn-close-sidebar" id="closeSidebar">×</button>
        </div>
        
        <div class="sidebar-content">
            <h3>侧边栏内容</h3>
            <p>这是一个滑动侧边栏模态框的内容区域。您可以在这里放置任何内容。</p>
            <ul style="margin-left: 20px; margin-bottom: 20px;">
                <li style="margin-bottom: 10px;">导航菜单项1</li>
                <li style="margin-bottom: 10px;">导航菜单项2</li>
                <li style="margin-bottom: 10px;">导航菜单项3</li>
            </ul>
            
            <div style="margin-top: 20px; padding: 15px; background: #f5f5f5; border-radius: 5px;">
                <p>这是一个内容区块,可以用来显示通知、设置选项等。</p>
                <button class="btn" style="display: block; width: 100%; margin-top: 10px;">操作按钮</button>
            </div>
        </div>
        
        <div class="sidebar-footer">
            <p>© 2023 侧边栏底部内容</p>
        </div>
    </div>
    
    <div class="overlay" id="overlay"></div>
    
    <script>
        document.addEventListener('DOMContentLoaded',  function() {
            const openBtn = document.getElementById('openSidebar'); 
            const closeBtn = document.getElementById('closeSidebar'); 
            const sidebar = document.getElementById('sidebarModal'); 
            const overlay = document.getElementById('overlay'); 
            
            // 打开侧边栏 
            openBtn.addEventListener('click',  function() {
                sidebar.classList.add('active'); 
                overlay.classList.add('active'); 
                document.body.style.overflow  = 'hidden';
            });
            
            // 关闭侧边栏 
            function closeSidebar() {
                sidebar.classList.remove('active'); 
                overlay.classList.remove('active'); 
                document.body.style.overflow  = 'auto';
            }
            
            closeBtn.addEventListener('click',  closeSidebar);
            overlay.addEventListener('click',  closeSidebar);
            
            // ESC键关闭 
            document.addEventListener('keydown',  function(e) {
                if (e.key  === 'Escape') {
                    closeSidebar();
                }
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值