3级菜单

<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <style>
        *{
            margin:0;
            padding:0;
        }

        ul{
            list-style: none;
        }

        body{
            background: #f5f5f5;
            font-family: "Microsoft YaHei";
            font-size: 12px;
        }
        .wrap{
            width:311px;
            margin:50px auto;
            padding:10px;
            border:1px #ddd solid;
            background: #fff;
        }

        .item{
            margin-bottom: 10px;
        }

        .item .title{
            height: 43px;
            background: url("images/zakladka.png") 0 0 no-repeat;
            padding-left:33px;
            line-height: 43px;
            color: #333;
            cursor: pointer;
        }

        .item .title span{
            display: block;
            width:26px;
            height: 37px;
            float: right;
            margin:3px 0 0 0;
            background: url("images/off.png") 0 0  no-repeat;
        }

        .item ul{
            margin:5px 0;
            padding: 0 10px 0 33px;
            overflow: hidden;
            transition:all 0.6s ease;
        }

        .item ul li{
            color:#8f9d4c;
            line-height:26px;
            cursor: pointer;
        }

        .item ul li:hover{
            text-decoration: underline;
        }

        .sublist{
            padding-left: 33px;
            /*height:0;*/
            overflow: hidden;
            transition:all 0.6s ease;
        }

        .item ul li span{
            display: block;
            width:26px;
            height: 26px;
            float: right;
            background: url("images/off.png") 0 -8px  no-repeat;
        }

    </style>
    <script>
        window.onload = function(){

            var uls = document.querySelectorAll("ul");
            var titles = document.querySelectorAll(".title");
            var ulh = [];
            var last;

            var subTile = document.querySelector(".sublist-title");
            var subSpan = document.querySelector(".arrow");
            var sublist = document.querySelector(".sublist");
            var subHeight = sublist.offsetHeight;

            //3级菜单显示隐藏
            sublist.style.height = 0;
            subTile.isShow = false;

            subTile.addEventListener("click",function(){
                var parent = this.parentNode;

                if(!this.isShow){
                    var p_height = parent.offsetHeight;

                    sublist.style.height = subHeight + "px";
                    parent.style.height = p_height + subHeight + "px";
                    this.isShow = true;

                    changeArrow(subSpan,true);
                }else{
                    var p_height = parent.offsetHeight;

                    sublist.style.height = 0;
                    parent.style.height = p_height - subHeight + "px";
                    this.isShow = false;

                    changeArrow(subSpan,false);
                }
            });

            //二级菜单
            for(var i = 0; i < uls.length;i++){
                var height = uls[i].offsetHeight;

                uls[i].style.height = 0;
                uls[i].isShow = false;
                ulh.push(height);
            }

            for(var i = 0; i < titles.length; i++){

                (function(i){
                    titles[i].addEventListener("click",function(){

                        if(last && last != uls[i]){
                            last.style.height = 0;
                            last.isShow = false;
                        }

                        if(!uls[i].isShow){
                            uls[i].style.height = ulh[i] + "px";
                            uls[i].isShow = true;
                        }else{
                            sublist.style.height = 0;
                            sublist.isShow = false;
                            uls[i].style.height = 0;
                            uls[i].isShow = false;
                        }    

                        last = uls[i];
                    });
                })(i);
            }

            //修改箭头
            function changeArrow(elem,state){
                var str;
                if(!state){
                    str = "url(‘images/off.png‘) 0 -5px no-repeat";
                }else{
                    str = "url(‘images/on.png‘) 0 -8px no-repeat";
                }
                elem.style.background = str;
            }
        }

    </script>

</head>
<body>

    <div class="wrap">

        <div class="item">
            <div class="title"><span></span>Item1</div>
            <ul>
                <li>subitem1</li>
                <li class="sublist-title">
                    <span class="arrow"></span>
                    subitem2
                    <div class="sublist">
                        <p>subItem1_1</p>
                        <p>subItem1_2</p>
                        <p>subItem1_3</p>
                        <p>subItem1_4</p>
                    </div>
                </li>
                <li>subitem3</li>
                <li>subitem4</li>
                <li>subitem5</li>
            </ul>
        </div>

        <div class="item">
            <div class="title"><span></span>Item1</div>
            <ul>
                <li>subitem1</li>
                <li>subitem2</li>
                <li>subitem3</li>
                <li>subitem4</li>
            </ul>
        </div>
        <div class="item">
            <div class="title"><span></span>Item1</div>
            <ul>
                <li>subitem1</li>
                <li>subitem2</li>
                <li>subitem3</li>
            </ul>
        </div>
    </div>

</body>
</html>

时间: 2024-08-26 02:06:04

3级菜单的相关文章

[伪] 级联菜单,两级菜单

[伪] 级联菜单,两级菜单 这段时间需要做一个类似效果的一个菜单样式,所以就查了各种文档,各种百度各种搜索,的确也是搜到了不少的第三方组件,比如(CascadingMenuViewLib)就是其中一个,但是,我脑子笨,研究了3天左右的时间,改不成我需要得样子,So...我用我自己的方式,实现了这个效果(对了,还没有完全实现,因为TextView被点中的样式我还没有设置,不过这都是小事情了..) 在这里,我提供一个思路,代码很简单,当然,我也会附一些上来,好的,我首先说一下思路 首先,我们的xml

【锋利的JQuery-学习笔记】菜单栏及其2级菜单

效果图: 鼠标移动到菜单项后如下: html: <div id="nav" class="mainNav"> <ul class="nav"> <li><a href="#">首 页</a></li> <li><a href="#">品 牌</a> <div class="jnNav&

DIV+CSS布局重新学习之css控制ul li实现2级菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

MFC 对话框中动态创建N级菜单以及响应事件

创建一个基于对话框的工程,工程名为CreateMenu 为该对话框增加一个文件菜单项和测试菜单项,如下图所示   测试菜单项至少要有一个子菜单项 在对话框属性中关联该菜单 在resource.h中增加一个ID_TESTMENU宏 #define ID_TESTMENU          5000 在对话框中添加一个Button按钮,建立消息映射,编辑代码如下 void CCreateMenuDlg::OnButton1() { // TODO: Add your control notifica

原生JS实现N级菜单

需求分析 简单的分析一下,要实现N级菜单,首先从布局入手,即判断是否有下级菜单 没有下一级菜单,直接排列 有下级菜单,又分为下级菜单排放位置,和在上级菜单显示类似 '>' 的符号,效果如图: 图:1 初步实现 1.实现是否存在   > 注意: 下面凡是担忧 xxx===yyy ? xxx : xxx都是利用三元表达式,来表达思路. HTML结构如下: 图:2 要实现图一的效果,我们只需要判断li标签里面的children.length===2 ? 'span存在' : 'span移除' 2.下

python练习_module01-1-3级菜单_2

3级菜单的另一种实现方式:循环 函数的方式:http://www.cnblogs.com/jailly/p/6709573.html 1.先创建一个能够表明3级目录结构之间映射关系的字典,然后将其存入一个pickle文件以便调用 1 import pickle 2 3 dir_windows = ['explorer.exe'] 4 part_C = {'windows': dir_windows} 5 6 dir_setup = ['rhel-7.3.iso', 'SecureCRT6.rar

(转)asp.net(C#)手记之Repeater与两级菜单

先来张图片说明下我们要实现的菜单: 这个菜单只实现了2级哈. 我采用的方法是嵌套2个Repeater. 先看下数据库中的表结构: 数据: 上代码: aspx: <asp:Repeater ID="rptMenus" runat="server" onitemdatabound="rptMenus_ItemDataBound"> <HeaderTemplate> <ul class="mnuLevel01&q

python-实现3级菜单(作业课)

1 #任务: 2 #显示3级菜单 3 #1级菜单#显示 3个城市 => 1北京 2上海 3广州 4 #2级菜单 #显示 选择1 北京 => B1 B2 B3 5 #2级菜单 #显示 选择2 上海 => S1 S2 S3 6 #2级菜单 #显示 选择3 广州 => G1 G2 G3 7 8 #3级菜单 #显示 选择B1 => b1_1 b1_2 b1_3 9 #3级菜单 #显示 选择B2 => b2_1 b2_2 b2_3 10 #3级菜单 #显示 选择B3 =>

C#中怎样在ToolStripMenuItem下再添加子级菜单

场景 在右键菜单ContextMenuStrip下添加子菜单选项可以通过 ContextMenuStrip menuStrip ToolStripMenuItem mnuChartOption = new ToolStripMenuItem(); //新建菜单项对象 mnuChartOption.Name = "chart_option"; mnuChartOption.Text = "图形选项"; //点击弹出图形选项对话框 mnuChartOption.Clic