web前端-二级分类菜单(类似购物网站)

效果:鼠标移上去右边显示二级菜单。

效果图:

实现代码

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        #nav{
            width:100%;
            height:420px;
            background-color:lightgrey;
        }
        #nav1{
            height:420px;
            width:1200px;
            background-color:lightblue;
            margin:0 auto;
        }
        #nav1 .menu{
            width:190px;
            height:420px;
            background:black;
            float:left;
        }
        #nav1 .flash{
            width:820px;
            height:420px;
            background:palevioletred;
            float:left;
        }
        #nav1 .news{
            width:190px;
            height:420px;
            background:greenyellow;
            float:left;
        }
        #nav1 .menu ul li{
            list-style-type:none;
            width:190px;
            height:69px;
            border-bottom:1px solid #1e1e1d;
            color:whitesmoke;
            text-indent:20px;
            position:relative;
        }
        #nav1 .menu ul li p{
            font-size:14px;
            color:whitesmoke;
        }
        /*构建二级菜单*/
        .menu ul li .more{
            width:300px;
            height:400px;
            background:black;
            position:absolute;
            left:189px;
            border:1px solid gray;
            display:none;
        }
        .menu ul li .border_top{
            height:1px;
            background:gray;
            width:190px;
            position:absolute;
            top:-1px;
            display:none;
        }
        .menu ul li .border_bottom{
            height:1px;
            background:gray;
            width:190px;
            position:absolute;
            bottom:-1px;
            display:none;
        }
        .menu ul li .border_right{
            height:70px;
            background:black;
            width:1px;
            position:absolute;
            right:0px;
            bottom:-1px;
            display:none;
        }
        #nav1 .menu ul li.hover .more{
            display:block;
        }
        #nav1 .menu ul li.hover .border_top{
            display:block;
        }
        #nav1 .menu ul li.hover .border_bottom{
            display:block;
        }
        #nav1 .menu ul li.hover .border_right{
            display:block;
        }

    </style>
</head>
<body>
<div id="nav">
    <div id="nav1">
        <div class="menu">
            <ul>
                <li>
                    <div class="more"></div>
                    <div class="border_top"></div>
                    <div class="border_bottom"></div>
                    <div class="border_right"></div>
                </li>
                <li>
                    <div class="more"></div>
                    <div class="border_top"></div>
                    <div class="border_bottom"></div>
                    <div class="border_right"></div>
                </li>
                <li>
                    <div class="more"></div>
                    <div class="border_top"></div>
                    <div class="border_bottom"></div>
                    <div class="border_right"></div>
                </li>
                <li>
                    <div class="more"></div>
                    <div class="border_top"></div>
                    <div class="border_bottom"></div>
                    <div class="border_right"></div>
                </li>
                <li>
                    <div class="more"></div>
                    <div class="border_top"></div>
                    <div class="border_bottom"></div>
                    <div class="border_right"></div>
                </li>
                <li>
                    <div class="more"></div>
                    <div class="border_top"></div>
                    <div class="border_bottom"></div>
                    <div class="border_right"></div>
                </li>
            </ul>
        </div>
        <div class="flash"></div>
        <div class="news"></div>
    </div>
</div>
<script src="jquery-2.1.0.min.js"></script>
<script>
    $(".menu ul li").hover(function(){
        var index=$(this).index();
        //鼠标移上去
        var top=$(this).position().top;//得到当前li到顶部的距离
        var height1=$(this).find(".more").height();//得到more盒子的高度
        var height=height1/3;
        //当top比当前盒子高度三分之一还大
        if(top>height){
            if(index==5){
                $(this).find(".more").css("bottom","-1px");
                $(this).addClass("hover");
            }else{
               $(this).find(".more").css("top","-"+height+"px");
                $(this).addClass("hover");
            }
        }else{
            $(this).find(".more").css("top","-1px");
            $(this).addClass("hover");
        }
    },function(){
        //鼠标移开
        $(this).removeClass("hover");
    });
</script>
</body>
</html>

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值