折叠菜单栏 选项卡效果

本文展示了如何使用JavaScript实现一个具有折叠菜单栏和选项卡切换效果的交互设计。点击后,菜单栏会展开并显示选项卡,每个选项卡可点击切换,右上角的关闭按钮可收起菜单栏,恢复初始状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先来看看效果图

首先默认显示的是爷爷,点击之后会先展开最下面一栏,然后出来上边的那部分,下面的兄弟五个是一个选项卡的效果,可以点击切换,点击右上角的关闭按钮就可以收回去,回到原来的样子,废话不多说,直接上代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>折叠菜单栏</title>
    <style>
        *{
            margin:0;
            padding: 0;
        }
        ul li {
            list-style: none;
        }
        #menu li{
            cursor: pointer;
        }
        #application{
            position:fixed;
            left: 0;
            bottom: 50%;
        }
        #icon{
            position: absolute;
            top: 0;
            left: 0;
            font-size: 12px;
            color: #fff;
            width: 30px;
            background: #000;
            padding:  6px 6px;
            cursor: pointer;
        }
        #list{
            position: absolute;
            left:-250px;
            top: 0;
            color: #A9A9A9;
            font-size: 12px;
            width: 250px;
        }
        #list ul{
            background: #222222;
            overflow: hidden;
        }
        #list ul li{
            float: left;
            padding: 6px 0;
            width: 50px;
            text-align: center;
        }
        #list  #menu .active{
            color: #002200;
            background: #eee;
            box-sizing: border-box;
            border-left: 1px solid #666;
            border-right: 1px solid #666;
            border-bottom: 1px solid #666;
        }
        #list #detail{
            position: absolute;
            left: 0;
            bottom: 28px;
            color: #020202;
            width: 100%;
            overflow: hidden;
            background:#666;
            height: 0;
        }
        #list #detail .panel{
            /*height: 100%;*/
            display: none;
            padding: 10px;
            font-size: 30px;
        }
        #list  #detail .active{
            display: block;
            height: 100%;
        }
        #delete{
            display: none;
            color: #ccc;
            padding: 10px ;
            font-size:14px;
            text-decoration: none;
            position: absolute;
            right: -250px;
            top: -220px;
        }
    </style>
</head>
<body>
    <div id="application">
        <div id="icon">爷爷</div>
        <div id="list">
            <ul id="menu">
                <li class="active">大伯</li>
                <li>二伯</li>
                <li>爸爸</li>
                <li>四叔</li>
                <li>五叔</li>
            </ul>
            <div id="detail">
                <div class="panel active">堂哥</div>
                <div class="panel">堂姐</div>
                <div class="panel">自己</div>
                <div class="panel">堂弟</div>
                <div class="panel">堂妹</div>
            </div>
        </div>
        <a href="javascript:;" id="delete" >&times;</a>
    </div>

    <script src="../common.js"></script>
    <script>
        var icon = $('icon'), list = $('list'), detail = $('detail'), menu = $( 'menu'), del = $( 'delete');
        var menuLi = Array.from( menu.children );
        var detailDiv = Array.from( detail.children );

        // 链式运动效果
        icon.onclick = function () {
            bufferMove(icon,{left: -icon.offsetWidth},function (){
                bufferMove(list,{left:0},function(){
                    bufferMove(detail,{height:220},function(){
                        del.style.display = 'block';
                    });
                });
            });
        };

        // 选项卡效果
        menuLi.forEach( (v,k) => {
            v.onclick = function () {
                //切换LI
                menuLi.forEach(n => n.className = '');
                this.className = 'active';

                //切换DIV
                detailDiv.forEach(n => n.style.display = 'none');
                detailDiv[k].style.display = 'block';
            };
        });

        // 删除效果
        del.onclick = function () {
            del.style.display = 'none';
            bufferMove(detail,{height:0},function () {
                bufferMove(list,{left:-250},function(){
                    bufferMove(icon,{left: 0});
                });
            });
        };
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值