jQuery隐藏UL,并且仅扩展一次特定的类集(有点像手风琴) [英] JQuery hide ULs and only expand once particular class set (bit like an accordion)
问题描述
正确的人,
在尝试执行我想做的JQuery手风琴之后,我认为隐藏了所有次要UL,并且仅在CMS自动设置了一个类后才扩展它们在lis上将是最简单的事情。我想拥有手风琴类型的功能,但是当该特定ul处于活动状态时,它必须扩展/向下滑动。我已经意识到典型的JQuery手风琴将不适合,因为在CMS菜单输出中将没有切换li的存在。
After battling with a JQuery Accordion trying to do what I want I think hiding all secondary UL's and only expanding them once a class my CMS sets automatically on lis would be the easiest thing. I want to have accordion type functionality, but it must expand/slide down when that particular ul is active. I have realized that a typical JQuery accordion will not suit, as I will not have toggle li's present in the CMS menu output.
此处的菜单代码:
<ul id="amenu">
<li><a href="anotherpage.html">Home</a></li><li><span class="currentbranch0">
<a href="anotherpage2.html">Content</a></span>
<ul class="multilevel-linkul-0" title="">
<li><a href="subpage.html">Content 2</a></li>
<li><span class="currentbranch1"><a href="subpage.html">Content 3</a></span></li>
</ul>
</li>
//How to target this command to multilevel-linkul-0 class?
$(function(){
$('ul li ul').slideDown();
});
(小提琴: http://jsfiddle.net/Dmhcq/5/ )
-更新了Fiddle以准确显示我的意思,我只希望使用currentbranch1的辅助UL向下滑动
-- Updated Fiddle to show exactly what I mean, I only want the secondary UL with currentbranch1 to slideDown
使用此代码,基本上任何具有span类 currentbranch1的东西都应向下滑动,其余的保持隐藏。
我一直在查看示例JQuery代码,即使从哪里开始也完全茫然,我不是JS程序员:)。因此,不幸的是,以上是我的最佳选择。
如果有人有任何建议,将不胜感激。 :)
With this code, basically anything with span class "currentbranch1" should slideDown and the rest should remain hidden. I have been looking at sample JQuery code and am completely at a loss even where to start, I'm not a JS programmer :) . So unfortunately above is my best stab at it. If anyone has any advice it would be much appreciated. :)
欢呼声
尼克
推荐答案
很简单。您需要反过来做。找到具有 currentbranch1类的元素,然后向上移动至 multilevel-linkul-0父级,并告诉其向下滑动。
It's simple. You need to do it the other way around. Find the element that has the class "currentbranch1" and traverse up to the "multilevel-linkul-0" parent and tell that to slide down.
代码
//How to target this command to multilevel-linkul-0 class?
$(function(){
$('.currentbranch1').parents('ul.multilevel-linkul-0').slideDown();
});
这里是小提琴的例子。
这篇关于jQuery隐藏UL,并且仅扩展一次特定的类集(有点像手风琴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!