gpt4 book ai didi

创建滑动侧边菜单时的 JQuery 问题

转载 作者:行者123 更新时间:2023-11-28 10:11:35 24 4
gpt4 key购买 nike

应该:

  1. 点击菜单中的标题
  2. 所有部分向上滑动
  3. 点击的部分向下滑动

发生了什么:

  1. 点击菜单中的标题
  2. 所有部分向上滑动
  3. 点击的部分向下滑动
  4. 所有部分都向下滑动!!

如何让点击的部分保持打开状态?

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;
}

最佳答案

这是您的 CSS(以及您对“ Accordion ”的拼写错误)和我对您的 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();
})
})

关于创建滑动侧边菜单时的 JQuery 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24354892/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com