简体   繁体   English

jQuery 中的手风琴菜单

[英]Accordion menu in jQuery

I am playing with a Accordion Menu plugin, specifically example 3 : Non-accordion (standard expandable menu).我正在玩手风琴菜单插件,特别是示例 3 :非手风琴(标准可扩展菜单)。

I am basically trying to use the example 3 option of this accordion menu by where I have 5 menu options, where two out of the five have sub-menus and the other three don't - they are just direct calls to a page.我基本上是在尝试使用此手风琴菜单的示例 3 选项,其中我有 5 个菜单选项,其中五个菜单选项中有两个具有子菜单,而其他三个没有-它们只是直接调用页面。

Example:例子:

Menu A菜单 A
Menu B菜单 B
Sub-Menu B1子菜单 B1
Sub-Menu B2子菜单 B2
Menu C菜单 C
Menu D菜单 D
Sub-Menu D1子菜单 D1
Sub-Menu D2子菜单 D2
Sub-Menu D3子菜单 D3
Sub-Menu D4子菜单 D4
Menu E菜单 E

Everything works fine but what I am after and unsure how to incorporate into the code is that if initially the whole menu is collapsed and I click on Menu B, which slides down sub-menu B content for this menu, what I am after is that as soon as I click on another menu option, say Menu A or even the other sub-menu option D, if there is an existing accordion menu expanded, I would like to see Menu B collapse when I click on either Menu A (no sub-menu) or Menu D (with sub-menu).一切正常,但我所追求的并且不确定如何合并到代码中的是,如果最初整个菜单被折叠并且我单击菜单 B,它会向下滑动此菜单的子菜单 B 内容,我所追求的是一旦我点击另一个菜单选项,比如菜单 A 甚至其他子菜单选项 D,如果现有的手风琴菜单展开,我希望当我点击菜单 A(没有子菜单)时看到菜单 B 折叠-menu)或菜单 D(带子菜单)。

How can I incorporate this functionality into this plugin, for example 3 from this website?如何将此功能合并到此插件中,例如来自本网站的 3?

From the source at the bottom of the page:从页面底部的来源:

[snip]

if($('#' + parent).hasClass('noaccordion')) {
    $(this).next().slideToggle('normal');
    return false;
}
...

Basically, this line trumps the others: if your accordion has the noaccordion class, it will not automatically close any open elements when you click another.基本上,这条线胜过其他:如果你的手风琴有noaccordion类,当你点击另一个时它不会自动关闭任何打开的元素。

Removing noaccordion from your ul 's markup would make it behave like the other examples, collapsing any open nodes when you click a different node.ul的标记中删除noaccordion会使它的行为与其他示例一样,当您单击不同的节点时会折叠所有打开的节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM