应该:
会发生什么:
如何让点击的部分保持打开状态?
JQuery的:
$(document).ready(function(){
$("#accordian h3").click(function(){
//slide up all the link lists
$("#accordian ul ul").slideUp();
//slide down the link list below the h3 clicked - only if its closed
if(!$(this).next().is(":visible"))
{
$(this).next().slideDown();
}
})
})
CSS:
/*custom font for text*/
@import url(http://fonts.googleapis.com/css?family=Nunito);
/*Basic reset*/
* {margin: 0; padding: 0;}
body {
background: #4EB889;
font-family: Nunito, arial, verdana;
}
#accordian {
background: #004050;
width: 250px;
margin: 100px auto 0 auto;
color: white;
/*Some cool shadow and glow effect*/
box-shadow:
0 5px 15px 1px rgba(0, 0, 0, 0.6),
0 0 200px 1px rgba(255, 255, 255, 0.5);
}
/*heading styles*/
#accordian h3 {
font-size: 12px;
line-height: 34px;
padding: 0 10px;
cursor: pointer;
/*fallback for browsers not supporting gradients*/
background: #003040;
/*background: linear-gradient(#003040, #002535);*/
@include linear-gradient(#003040, #002535);
}
/*heading hover effect*/
#accordian h3:hover {
text-shadow: 0 0 1px rgba(255, 255, 255, 0.7);
}
/*iconfont styles*/
#accordian h3 span {
font-size: 16px;
margin-right: 10px;
}
/*list items*/
#accordian li {
list-style-type: none;
}
/*links*/
#accordian ul ul li a {
color: white;
text-decoration: none;
font-size: 11px;
line-height: 27px;
display: block;
padding: 0 15px;
/*transition for smooth hover animation*/
transition: all 0.15s;
}
/*hover effect on links*/
#accordian ul ul li a:hover {
background: #003545;
border-left: 5px solid lightgreen;
}
/*Lets hide the non active LIs by default*/
#accordian ul ul {
display: none;
}
#accordian li.active ul {
display: block;
}
答案 0 :(得分:0)
这是你的CSS(以及你的拼写错误"手风琴")以及我对你的HTML的最佳猜测。一个小的修改似乎工作正常。我已添加not()
方法来过滤当前子列表。同样,不需要if语句检查可见性。
http://jsfiddle.net/isherwood/ZAutZ/2
$(document).ready(function(){
$("#accordian h3").click(function(){
// slide up all the link lists
$("#accordian ul ul").not( $(this).next() ).slideUp();
// slide down this one
$(this).next().slideDown();
})
})