• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

jQuery垂直可折叠展开导航菜单代码实例

jquery 程序员 6年前 (2019-03-27) 281次浏览 已收录 0个评论

本章节分享一段代码实例,它实现了垂直可展开和折叠的导航菜单效果。

代码实例如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.gaodaima.com/" />
<title>搞代码</title>
<style type="text/css">
* {
  margin: 0;
  padding: 0;
}
.menu_list {
  width: 268px;
  margin: 0 auto;
}
.menu_head {
  height: 47px;
  line-height: 47px;
  padding-left: 38px;
  font-size: 14px;
  color: #525252;
  cursor: pointer;
  border-left: 1px solid #e1e1e1;
  border-right: 1px solid #e1e1e1;
  border-bottom: 1px solid #e1e1e1;
  border-top: 1px solid #F1F1F1;
  position: relative;
  margin: 0px;
  font-weight: bold;
  background: #f1f1f1 url(demo/jQuery/img/jia.png) center right no-repeat;
}
.menu_list .current {
  background: #f1f1f1 url(demo/jQuery/img/jian.png) center right no-repeat;
}
.menu_body {
  line-height: 38px;
  border-left: 1px solid #e1e1e1;
  background: #fff;
  border-right: 1px solid #e1e1e1;
}
.menu_body a {
  display: block;
  height: 38px;
  line-height: 38px;
  padding-left: 38px;
  color: #777777;
  background: #fff;
  text-decoration: none;
  border-bottom: 1px solid #e1e1e1;
}
.menu_body a:hover {
  text-decoration: none;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
$(document).ready(function () {
  $("#firstpane h3.menu_head").click(function () {
    $(this).addClass("current")
    .next("div.menu_body")
    .slideToggle(300)
    .siblings("div.menu_body")
    .slideUp("slow");
    $(this).siblings().removeClass("current");
  });
});
</script>
</head>
<body>
  <div id="firstpane" class="menu_list">
    <h3 class="menu_head">搞代码</h3>
    <div style="display:none" class="menu_body">
      <a href="#">div教程</a>
      <a href="#">css教程</a>
      <a href="#">js教程</a>
      <a href="#">css3教程</a>
      <a href="#">json教程</a>
      <a href="#">ajax教程</a>
      <a href="#">es6教程</a>
      <a href="#">jquery教程</a>
    </div>
    <h3 class="menu_head">资源下载</h3>
    <div style="display:none" class="menu_body">
      <a href="#">特效下载</a>
      <a href="#">移动端下载</a>
      <a href="#">模板下载</a>
      <a href="#">源码下载</a>
      <a href="#">图片下载</a>
    </div>
    <h3 class="menu_head">前端网站</h3>
    <div style="display:none" class="menu_body">
      <a href="#">搞代码</a>
      <a href="#">gaodaima.com</a>
      <a href="#">前端专区</a>
      <a href="#">资源专区</a>
    </div>
  </div>
</body>
</html>

jQuery垂直可折叠展开导航菜单代码实例


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:jQuery垂直可折叠展开导航菜单代码实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址