html5树形菜单代码,jquery实现树形菜单完整代码

本实例实现了树形的动态菜单,兼容IE8,火狐,Chrome等浏览器。使用了jQuery的toggle() 方法。效果和代码如下:

78709d817769d69410858bf1be9df817.png

jquery的树形菜单代码

body { font-family:"宋体"; font-size: 12px; line-height: 1.5em; color:#7FB0C8; padding:0; margin:0; background: #336699;}

ul,ol,li,dl,dt,dd { margin:0; padding:0; list-style-type:none;}

h1,h2,h3,form,input,iframe,span { margin:0; padding:0;}

a { color:#7FB0C8;}

a:link {color: #7FB0C8; TEXT-DECORATION: none;}

a:visited {color: #7FB0C8; TEXT-DECORATION: none;}

a:hover {color: #fff; TEXT-DECORATION: none;}

.white { color:#fff;}

.white a:link {color: #fff; TEXT-DECORATION: none;}

.white a:visited {color: #fff; TEXT-DECORATION: none;}

.white a:hover {color: #73E1F5; TEXT-DECORATION: none;}

/* 树形菜单开始 */

.close { float:right; clear:right; font-size:12px; font-weight:normal; cursor:pointer; padding-right:10px;}

.title { font-size:14px; color:#fff; margin-bottom:10px; padding-left:5px; width:290px;}

.menu { width:290px; height:330px; margin-bottom:10px;}

.l1 { background:#000; font-size:13px; padding:5px 0 0 30px; height:20px; margin-bottom:5px; cursor:pointer;}

.slist { margin:0 0 5px 0; display:none;}

.l2 { padding:0 0 0 35px; font-size:13px;}

.l2 a { padding:6px 0 0 5px; width:230px; height:21px; display:block;}

.currentl2 a,.l2 a:hover { background:#1E5A82; color:#fff;}

.sslist { background:#156890; width:235px; overflow:hidden; margin:0 0 5px 35px; display:none;}

.l3 a { padding:6px 0 0 5px; width:230px; height:20px; display:block;}

.currentl3 a,.l3 a:hover { color:#fff; font-weight:bold;}

// 树状菜单

$(document).ready(function () {

$(".l1").toggle(function () {

$(".slist").animate({ height: 'toggle', opacity: 'hide' }, "slow");

$(this).next(".slist").animate({ height: 'toggle', opacity: 'toggle' }, "slow");

}, function () {

$(".slist").animate({ height: 'toggle', opacity: 'hide' }, "slow");

$(this).next(".slist").animate({ height: 'toggle', opacity: 'toggle' }, "slow");

});

$(".l2").toggle(function () {

$(this).next(".sslist").animate({ height: 'toggle', opacity: 'toggle' }, "slow");

}, function () {

$(this).next(".sslist").animate({ height: 'toggle', opacity: 'toggle' }, "slow");

});

$(".l2").click(function () {

$(".l3").removeClass("currentl3");

$(".l2").removeClass("currentl2");

$(this).addClass("currentl2");

});

$(".l3").click(function () {

$(".l3").removeClass("currentl3");

$(this).addClass("currentl3");

});

$(".close").toggle(function () {

$(".slist").animate({ height: 'toggle', opacity: 'show' }, "fast");

$(".sslist").animate({ height: 'toggle', opacity: 'show' }, "fast");

}, function () {

$(".slist").animate({ height: 'toggle', opacity: 'hide' }, "fast");

$(".sslist").animate({ height: 'toggle', opacity: 'hide' }, "fast");

});

});

全部收起/展开Jihua树形菜单

本实例用到jquery的toggle() 方法,介绍如下:

定义和用法

toggle() 方法切换元素的可见状态。

如果被选元素可见,则隐藏这些元素,如果被选元素隐藏,则显示这些元素。

语法

$(selector).toggle(speed,callback,switch)

e8b256dbfb1bd5bc79cdd8eb35f23314.png

提示和注释

注释:该效果适用于通过 jQuery 隐藏的元素,或在 CSS 中声明 display:none 的元素(但不适用于 visibility:hidden 的元素)。

以上就是jquery实现树形菜单完整代码,希望对大家的学习jquery程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值