jQuery实现多级手风琴树形下拉菜单(源码)

前几天因为公司的菜单要调整,公司的UI框架是不支持的,所以就自己在网上找了一个下拉菜单,可以支持多级菜单数据的,菜单数据是从xml文件中配置后读取的,网上有许多这方面的例子感觉不是很好用,就打了个包贴在园子里了。效果图片如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAp8AAAH2CAIAAAC5mXBQAAAgAElEQVR4nO3cv23jaru1cVbBMgiwCDehhDW4CCXsYFpQwgoGcOBAwREEcAMK3kCAQkUOGX5fQJF69M+2lq172ZzrFxzssWXZe58X69JD0ZP9PwAAMC2Z+wcAAADfjLoDADA11B0AgKmh7gAATA11BwBgaqg7AABTQ90BAJga6g4AwNRQdwAApoa6AwAwNdQdAICpoe4AAEwNdQcAYGqoOwAAU0PdAQCYGuoOAMDUUHcAAKaGugMAMDXUHQCAqaHuUHQAfi33fiACdYfCvU4AdO79QATqDoV7nQDo3PuBCNQdCvc6AdC59wMRqDsU7nUCoHPvByJQdyjc6wRA594PRKDuULjXCYDOvR+IQN2hcK8TAJ17PxCBukPhXicAOvd+IAJ1h8K9TgB07v1ABOoOhXudAOjc+4EI1B0K9zoB0Ln3AxGoOxTudQKgc+8HIlB3KNzrBEDn3g9EoO5QuNcJgM69H4hA3aFwrxMAnXs/EIG6Q+FeJwA6934gAnWHwr1OAHTu/UAE6g6Fe50A6Nz7gQjUHQr3OgHQufcDEag7FNKktGWWZVnZ3v5IM6+yT6jmzZf3Dfh3ufcDEag7FNqm9PHOi2rXdV3X1bPy/VT3jy9ntfbtAFzl3g9EoO5Q3DUlfcU/dFHxXVXkWZbVi/b68wKQuPcDEag7FF9Zlv5EfuvI3i7q918EEHvgi9z7gQjUHYp71+TDZo+x7x95tf39ywLqDnyRez8QgbpDce+a9M2++g762VH+tO79xfnDbXfUHfgW7v1ABOoOxb1rop7dqTvw/dz7gQjUHYp710Q9u7dlco89dQe+hXs/EIG6Q3Hvmmhn9/Gr+sBTd+BbuPcDEag7FPeuyefP7qPd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ADA11B0AgKmh7gAATA11BwBgaqg7AABTQ90BAJga6g4AwNRQdwAApoa6AwAwNdQdAICpoe4AAEwNdQcAYGqoOwAAU0PdAQCYGuoOAMDUUHcAAKaGugMAMDXUHQCAqaHuAABMDXUHAGBqqDsAAFND3QEAmJr/D3aXsV89/izIAAAAAElFTkSuQmCC" alt="" />

上图片展示的是三级,应该还可以根据自己的需要扩展多级的。

不想下载的朋友可以直接复制源码内容,总共三个文件,一个html文件,另外一个是js扩展库,还有一个是jquery库在这里使用的是gg的一个包:

index.html

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery实现多级手风琴菜单</title>
<meta name="keywords" content="多级下拉菜单, jquery插件" />
<meta name="description" content="XHTML、CSS、jquery、PHP案例和示例" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="accordion.js"></script>
<script type="text/javascript">
$(function(){
$(".nav").accordion({
//accordion: true,
speed: ,
closedSign: '[+]',
openedSign: '[-]'
});
});
</script>
<style>
ul{list-style:none}
.demo{width:300px; margin:40px auto; padding:10px; background:#f7f7f7}
.nav {width: 213px; padding: 40px 28px 25px ; font-family: "Microsoft yahei", Arial, Helvetica, sans-serif;}
ul.nav {padding: ; margin: ; font-size: 1em; line-height: .5em; list-style: none;}
ul.nav li {}
ul.nav li a {line-height: 10px; font-size: 14px; padding: 10px 5px; color: #; display: block; text-decoration: none; font-weight: bolder;}
ul.nav li a:hover {background-color:#675C7C; color:white;}
ul.nav ul { margin: ; padding: ;display: none;}
ul.nav ul li { margin: ; padding: ; clear: both;}
ul.nav ul li a { padding-left: 20px; font-size: 12px; font-weight: normal;}
ul.nav ul li a:hover {background-color:#D3C99C; color:#675C7C;}
ul.nav ul ul li a {color:silver; padding-left: 40px;}
ul.nav ul ul li a:hover { background-color:#D3CEB8; color:#675C7C;}
ul.nav span{float:right;}
</style>
</head> <body>
<div id="main"> <div class="demo">
<ul class="nav">
<li><a href="http://renzaijianghu.cnblogs.com" target="_blank">首页</a></li>
<li><a href="#">服务</a>
<ul>
<li><a href="#">JAVASCRIPT</a></li>
<li><a href="#">PHP</a></li>
<li><a href="#">MYSQL</a></li>
<li><a href="#">LINUX</a></li>
</ul>
</li>
<li><a href="#">案例</a></li>
<li><a href="#">文章</a></a>
<ul>
<li class="active"><a href="http://renzaijianghu.cnblogs.com" target="_blank">XHTML/CSS</a></li>
<li><a href="#">Javascript/Ajax/jQuery</a>
<ul>
<li><a href="#">Cookies</a></li>
<li><a href="#">Event</a></li>
<li><a href="#">Games</a></li>
<li><a href="#">Images</a></li>
</ul>
</li>
<li><a href="http://renzaijianghu.cnblogs.com" target="_blank">PHP/MYSQL</a></li>
<li><a href="http://renzaijianghu.cnblogs.com" target="_blank">前端观察</a></li>
<li><a href="http://renzaijianghu.cnblogs.com" target="_blank">HTML5/移动WEB应用</a></li>
</ul>
</li>
<li><a href="http://renzaijianghu.cnblogs.com/about.html" target="_blank">关于</a></li>
</ul>
</div>
</div> </body>
</html>

accordion.js

/*
* jQuery UI Multilevel Accordion v.1
*
* Copyright (c) 2011 Pieter Pareit
*
* http://www.scriptbreaker.com
*
*/ //plugin definition
(function($){
$.fn.extend({ //pass the options variable to the function
accordion: function(options) { var defaults = {
accordion: 'true',
speed: ,
closedSign: '[+]',
openedSign: '[-]'
}; // Extend our default options with those provided.
var opts = $.extend(defaults, options);
//Assign current element to variable, in this case is UL element
var $this = $(this); //add a mark [+] to a multilevel menu
$this.find("li").each(function() {
if($(this).find("ul").size() != ){
//add the multilevel sign next to the link
$(this).find("a:first").append("<span>"+ opts.closedSign +"</span>"); //avoid jumping to the top of the page when the href is an #
if($(this).find("a:first").attr('href') == "#"){
$(this).find("a:first").click(function(){return false;});
}
}
}); //open active level
$this.find("li.active").each(function() {
$(this).parents("ul").slideDown(opts.speed);
$(this).parents("ul").parent("li").find("span:first").html(opts.openedSign);
}); $this.find("li a").click(function() {
if($(this).parent().find("ul").size() != ){
if(opts.accordion){
//Do nothing when the list is open
if(!$(this).parent().find("ul").is(':visible')){
parents = $(this).parent().parents("ul");
visible = $this.find("ul:visible");
visible.each(function(visibleIndex){
var close = true;
parents.each(function(parentIndex){
if(parents[parentIndex] == visible[visibleIndex]){
close = false;
return false;
}
});
if(close){
if($(this).parent().find("ul") != visible[visibleIndex]){
$(visible[visibleIndex]).slideUp(opts.speed, function(){
$(this).parent("li").find("span:first").html(opts.closedSign);
}); }
}
});
}
}
if($(this).parent().find("ul:first").is(":visible")){
$(this).parent().find("ul:first").slideUp(opts.speed, function(){
$(this).parent("li").find("span:first").delay(opts.speed).html(opts.closedSign);
}); }else{
$(this).parent().find("ul:first").slideDown(opts.speed, function(){
$(this).parent("li").find("span:first").delay(opts.speed).html(opts.openedSign);
});
}
}
});
}
});
})(jQuery);

源码下载

上一篇:剑指Offer - 九度1510 - 替换空格


下一篇:xml解析,练习