基于jquery实现的折叠式菜单

 1、源码

以下是源码,很方便的能引入的自己项目中

<!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-Type" content="text/html; charset=utf-8" />
<title>jqueryTest</title>
<script type="text/javascript" src="../js/jquery-1.3.2.js" ></script>
<style type="text/css">
	body,div{ margin:0;padding:0;}
	#menu {width:200px;}
	.has_children{  
		 background:url(../image/bg_title.gif) no-repeat;
		 padding:8px 0 8px 25px;
		 font-weight:bold; 
		 cursor:pointer; 
		 margin:0;
		 display:block;
	}
	.highlight{
		 background:url(../image/bg_title_visited.gif) no-repeat;
		 padding:8px 0 8px 25px;
		 color:#f59000;
		 font-weight:bold; 
		 cursor:auto; 
		 margin:0;
		 display:block;
	}
	.highlight a{
		margin-top:10px;
	}
  a:hover {
		color: #000000;
		background-color:#dfdfdf;
		text-decoration:underline;
		font-weight:normal;
		margin-top:10px;
    }
	.has_children a{ 
		display:none; 
		width:auto;
	}
</style>
<script type="text/javascript">
 $(function(){
 	$(".has_children").click( function(){ //元素
		$(this).siblings().filter(".highlight").children("a").slideToggle("normal");
		$(this).end().siblings().filter(".highlight").children("a").slideToggle("normal");
		if($(this).children("a").is(":hidden"))//隐藏
		{
			$(this).children("a").slideToggle("normal");//slideToggle 隐藏或者显示
			$(this).removeClass("has_children");
			$(this).addClass("highlight");
		}else{
			$(this).children("a").slideToggle("normal");//slideToggle 隐藏或者显示
			$(this).removeClass("highlight");
			$(this).addClass("has_children");
		}
		$(this).siblings().filter(".highlight").removeClass("highlight").addClass("has_children");
	});
	
});
</script>
</head>

<body>
	<div id="menu">
		<div class="has_children">
			<span>研发中心</span>
			<a href="#">研发中心一部</a>
			<a href="#">研发中心二部</a>
			<a href="#">研发中心三部</a>
			<a href="#">研发中心四部</a>
			<a href="#">研发中心五部</a>
		</div>
		<div class="has_children">
			<span>销售部</span>
			<a href="#">华北区</a>
			<a href="#">华南区</a>
			<a href="#">东北区</a>
			<a href="#">江南区</a>
		</div>
		<div class="has_children">
			<span>行政部</span>
			<a href="#">行政部所有人员</a>
			<a href="#">行政部所有人1员</a>
			<a href="#">行政部所有人2员</a>
		</div>
		<div class="has_children">
			<span>行政1部</span>
			<a href="#">行政部所有人1员</a>
			<a href="#">行政部所有人11员</a>
			<a href="#">行政部所有人12员</a>
		</div>
	</div>
</body>
</html>

2、资源图片

所需要的两张图片

3、执行效果

225621_yD8e_2391658.png

转载于:https://my.oschina.net/u/2391658/blog/712831

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值