博客
关于我
基于jquery的简洁树形折叠菜单
阅读量:445 次
发布时间:2019-03-06

本文共 2926 字,大约阅读时间需要 9 分钟。

先上效果图:

最小的ul就是一个最小的树枝,空间允许时可无限扩展。html如下:

css如下:

div.panel:first-child {    margin-top:20px;}div.treeview {    min-width: 100px;    min-height: 100px;        max-height: 256px;    overflow:auto;        padding: 4px;        margin-bottom: 20px;        color: #369;        border: solid 1px;    border-radius: 4px;}div.treeview ul:first-child:before {    display: none;}.treeview, .treeview ul {    margin:0;    padding:0;    list-style:none;        color: #369;}.treeview ul {    margin-left:1em;    position:relative}.treeview ul ul {    margin-left:.5em}.treeview ul:before {    content:"";    display:block;    width:0;    position:absolute;    top:0;    left:0;    border-left:1px solid;    bottom:15px;}.treeview li {    margin:0;    padding:0 1em;    line-height:2em;    font-weight:700;    position:relative}.treeview ul li:before {    content:"";    display:block;    width:10px;    height:0;    border-top:1px solid;    margin-top:1px;    position:absolute;    top:1em;    left:0}.tree-indicator {    margin-right:5px;        cursor:pointer;}.treeview li a {    text-decoration: none;    color:inherit;        cursor:pointer;}.treeview li button, .treeview li button:active, .treeview li button:focus {    text-decoration: none;    color:inherit;    border:none;    background:transparent;    margin:0px 0px 0px 0px;    padding:0px 0px 0px 0px;    outline: 0;}

js如下:

$.fn.extend({    treeview:    function() {        return this.each(function() {            var tree = $(this);            tree.addClass('treeview-tree');            tree.find('li').each(function() {                var stick = $(this);            });            tree.find('li').has("ul").each(function () {                var branch = $(this); //li with children ul                branch.prepend(">");                branch.addClass('tree-branch');                branch.on('click', function (e) {                    if (this == e.target) {                        var icon = $(this).children('i:first');                        $(this).children().children().toggle();                    }                })                branch.children().children().toggle();                branch.children('.tree-indicator, button, a').click(function(e) {                    branch.click();                    e.preventDefault();                });            });        });    }});//调用$(window).on('load', function () {    $('.treeview').each(function () {        var tree = $(this);        tree.treeview();    })})

 

转载地址:http://ziufz.baihongyu.com/

你可能感兴趣的文章
logstash mysql 准实时同步到 elasticsearch
查看>>
Luogu2973:[USACO10HOL]赶小猪
查看>>
mabatis 中出现< 以及> 代表什么意思?
查看>>
Mac book pro打开docker出现The data couldn’t be read because it is missing
查看>>
MAC M1大数据0-1成神篇-25 hadoop高可用搭建
查看>>
mac mysql 进程_Mac平台下启动MySQL到完全终止MySQL----终端八步走
查看>>
Mac OS 12.0.1 如何安装柯美287打印机驱动,刷卡打印
查看>>
MangoDB4.0版本的安装与配置
查看>>
Manjaro 24.1 “Xahea” 发布!具有 KDE Plasma 6.1.5、GNOME 46 和最新的内核增强功能
查看>>
mapping文件目录生成修改
查看>>
MapReduce程序依赖的jar包
查看>>
mariadb multi-source replication(mariadb多主复制)
查看>>
MariaDB的简单使用
查看>>
MaterialForm对tab页进行隐藏
查看>>
Member var and Static var.
查看>>
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>