html折叠 手风琴效果,jQuery制作效果超棒的手风琴折叠菜单

本文介绍了一种使用jQuery制作的手风琴折叠菜单,通过优化的JavaScript代码实现,点击标题展开或收起子菜单。文章提供了详细的代码示例和HTML结构,适合学习jQuery和前端交互设计的读者参考。
摘要由CSDN通过智能技术生成

拉风的jQuery制作的手风琴折叠菜单,效果非常不错!这里是之前版本的改进版,主要是jquery代码改进

演示图:

296ef57b7d8d52f627a3a6a59a549eb2.png

b810a429ab1cefa6864b8c09be2e5a14.png

2d32d8041f445632e56ec091b9a44b07.png

main.js

$(function(){

var tmp = null,

$title = $('.title'),

$con = $('.title > ul');

$title.click(function(){

$(tmp).children('ul').slideUp().end().children('.arrow').removeClass('arrow-up');

$(this).children('ul').slideToggle().end().children('.arrow').addClass('arrow-up');

tmp = this;

});

$con.click(function(){

return false; // 阻止事件冒泡

});

});

index.html

jquery js css html

style.css

/*globle*/

ul, li{

margin: 0;

padding: 0;

list-style-type: none;

}

a{

display: inline-block;

width: 100%;

height: 31px;

text-decoration: none;

color: #fff;

font-size: 13px;

}

a:hover{

background: #52718A;

}

/*sidebar*/

.sidebar{

width: 210px;

height: 335px;

margin: 50px auto;

border-radius: 5px;

font: 14px '新宋体';

color: #f4f4f4;

}

.title{

width: 95%;

line-height: 32px;

border-bottom: 1px solid #ccc;

background: #1ABC9C;

cursor: pointer;

}

.title > span{

margin-left: 10px;

}

/*in-sidebar*/

.in-sidebar{

width: 100%;

display: none;

}

.in-sidebar > li{

width: 100%;

height: 32px;

background: #34495E;

line-height: 32px;

text-align: center;

border-bottom: 1px solid #ddd;

}

/*arrow*/

.arrow{

float: right;

display: inline-block;

margin-right: 5px;

width: 20px;

height: 32px;

background: url(../img/down.png) no-repeat center;

}

.arrow-up{

background: url(../img/up.png) no-repeat center;

}

以上所述就是本文给大家分享的全部内容了,希望能够对大家学习jQuery有所帮助。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值