jquery自制折叠菜单
2016-04-04 09:54
429 查看
利用jquery可以轻松的制作折叠菜单,先来看看效果图吧:
当点击每个标题时会下来,再次点击会滑动收缩,接下来看看具体的实现代码吧:
<!DOCTYPE html>
<html>
<head>
<title>jQuery 自制折叠菜单</title>
<meta charset="UTF-8">
<script type="text/javascript" src="js/jquery.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
.toggle { width:250px; }
.toggle dl dt { border-top:1px solid #D1D1D1;
border-bottom:1px solid white;background:#E6E9EE; height:40px; width:100%; line-height:40px; font-size:14px; font-weight:bold; color:#2E3442; cursor:pointer;display:block; }
.toggle dl dt:hover{background-color: #3A9EFC;color: white;}
.toggle dl dd { line-height:24px; }
.toggle dl dd ul li {
cursor: pointer;line-height: 30px;font-size: 12px;margin-left: 20px;}
.toggle dl dd ul li:hover{color: #1C63BF; }
#bigcon{margin-top: 95px;float: left;border: 1px solid #CAD1D7;margin-left: 10px;}
#conhd{width: 100%;height: 40px;border-bottom: 1px solid #0057B0;}
#conmain{width: 100%;border: 1px solid #006600;}
</style>
<script type="text/javascript">
$(function(){
$(".toggle dl dd").hide();
$(".toggle dl dt").click(function(){
$(".toggle dl dd").not($(this).next()).slideUp();
$(this).next().slideToggle(500);
});
});
</script>
</head>
<body>
<div class="toggle">
<dl>
<dt>标题一</dt>
<dd>
<ul>
<li>标题一的子标题一</li>
<li>子标题二</li>
<li>标题一的子标题三</li>
</ul>
</dd>
</dl>
<dl>
<dt>标题二</dt>
<dd>
<ul>
<li>标题二的子标题一</li>
<li>子标题二</li>
<li>标题二的子标题三</li>
</ul>
</dd>
</dl>
<dl>
<dt>标题三</dt>
<dd>
<ul>
<li>标题三的子标题一</li>
<li>子标题二</li>
<li>标题三的子标题三</li>
</ul>
</dd>
</dl>
</div>
</body>
</html>
当点击每个标题时会下来,再次点击会滑动收缩,接下来看看具体的实现代码吧:
<!DOCTYPE html>
<html>
<head>
<title>jQuery 自制折叠菜单</title>
<meta charset="UTF-8">
<script type="text/javascript" src="js/jquery.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
.toggle { width:250px; }
.toggle dl dt { border-top:1px solid #D1D1D1;
border-bottom:1px solid white;background:#E6E9EE; height:40px; width:100%; line-height:40px; font-size:14px; font-weight:bold; color:#2E3442; cursor:pointer;display:block; }
.toggle dl dt:hover{background-color: #3A9EFC;color: white;}
.toggle dl dd { line-height:24px; }
.toggle dl dd ul li {
cursor: pointer;line-height: 30px;font-size: 12px;margin-left: 20px;}
.toggle dl dd ul li:hover{color: #1C63BF; }
#bigcon{margin-top: 95px;float: left;border: 1px solid #CAD1D7;margin-left: 10px;}
#conhd{width: 100%;height: 40px;border-bottom: 1px solid #0057B0;}
#conmain{width: 100%;border: 1px solid #006600;}
</style>
<script type="text/javascript">
$(function(){
$(".toggle dl dd").hide();
$(".toggle dl dt").click(function(){
$(".toggle dl dd").not($(this).next()).slideUp();
$(this).next().slideToggle(500);
});
});
</script>
</head>
<body>
<div class="toggle">
<dl>
<dt>标题一</dt>
<dd>
<ul>
<li>标题一的子标题一</li>
<li>子标题二</li>
<li>标题一的子标题三</li>
</ul>
</dd>
</dl>
<dl>
<dt>标题二</dt>
<dd>
<ul>
<li>标题二的子标题一</li>
<li>子标题二</li>
<li>标题二的子标题三</li>
</ul>
</dd>
</dl>
<dl>
<dt>标题三</dt>
<dd>
<ul>
<li>标题三的子标题一</li>
<li>子标题二</li>
<li>标题三的子标题三</li>
</ul>
</dd>
</dl>
</div>
</body>
</html>
相关文章推荐
- jquery给h1和span赋值
- Jquery Table 的基本操作
- jQuery源码浅析
- jQuery UI 知识点
- jquery-ui以及js复习
- jquery
- jQuery Ajax全解析
- jQuery
- svg使用小计(二)
- 谈谈jQuery和js里有关位置和宽高的方法
- jquery attr()和prop()方法的使用
- html基础开发-- Jquery框架方法使用(攻略二)
- Html Css Javascripe jQuery 速成经验 support by Mr song 第五周作业
- JavaScript之jQuery-10 T-Query(T-Query、基本选择器、T-Query对象、操作方法、创建元素、事件绑定)
- jquery实现ajax实例
- JavaScript之jQuery-9 jQuery 开发插件(添加新全局函数、添加jQuery对象方法、添加新简写方法、方法参数)
- jQuery代码优化:事件委托篇
- jquery-ajax-php(内容点赞并进行cookie限制实现)
- JavaScript之jQuery-8 jQuery 使用插件(zTree树插件、jQuery UI插件)
- jQuery实现图片轮播且鼠标可控制显示,使用animate函数