jQuery UI API - folding panel member (Accordion Widget)
category
usage
Description: converting one pairs title and content of the panel is folded into a panel.
New Version: 1.0
Folding panel labeled containers need a title and content of the panel.
<Div id = "accordion"> <H3> First header </ h3> <Div> First content panel </ div> <H3> Second header </ h3> <Div> Second content panel </ div> </ Div>
Folding panel support any tag, but the contents of each panel must be at the same level associated with a head panel. See the header
options on how to use the custom tag structure.
Panel can be set active
programmatically activate the option.
Keyboard interaction
When the focus is in the title (header) on, the following keyboard commands are available:
- UP / LEFT - Move cursor to a title (header). If the first title (header), the focus will move to the last title (header) on.
- DOWN / RIGHT - Move cursor to the next title (header). If at the end of a title (header), the focus will move to the first title (header) on.
- HOME - Move cursor to the first title (header) on.
- END - Move cursor to the last title (header) on.
- SPACE / ENTER - activates the focused title (header) associated panel (panel).
When the (panel) when the focus is on the panel, the following keyboard commands are available:
- CTRL + UP: Move cursor to the relevant title (header).
Theming
Folding panel member (Accordion Widget) using jQuery UI CSS framework to define the look and feel of its style. If you need to use the specified style folding panel, you can use the following CSS class name:
-
ui-accordion
: folding panel outer container.-
ui-accordion-header
: accordion title. If the title containsicons
, the title would otherwise have aui-accordion-icons
, class. -
ui-accordion-content
: accordion content panels.
-
rely
- UI core (UI Core)
- Component Library (Widget Factory)
- Effects Core (Core Effects) (optional; when and
animate
when used with options)
Additional information
- The part requires some functional CSS, otherwise it will not work. If you create a custom theme, use the widget specified CSS file as a starting point.
Quick navigation
选项 | 方法 | 事件 |
---|---|---|
选项 | 类型 | 描述 | 默认值 |
---|---|---|---|
active | Boolean 或 Integer | 当前打开哪一个面板。 支持多个类型:
代码实例: 初始化带有指定 $( ".selector" ).accordion({ active: 2 }); 在初始化后,获取或设置 // getter var active = $( ".selector" ).accordion( "option", "active" ); // setter $( ".selector" ).accordion( "option", "active", 2 ); |
0 |
animate | Boolean 或 Number 或 String 或 Object | 是否使用动画改变面板,且如何使用动画改变面板。 支持多个类型:
代码实例: 初始化带有指定 $( ".selector" ).accordion({ animate: "bounceslide" }); 在初始化后,获取或设置 // getter var animate = $( ".selector" ).accordion( "option", "animate" ); // setter $( ".selector" ).accordion( "option", "animate", "bounceslide" ); |
{} |
collapsible | Boolean | 所有部分是否都可以马上关闭。允许折叠激活的部分。 代码实例: 初始化带有指定 $( ".selector" ).accordion({ collapsible: true }); 在初始化后,获取或设置 // getter var collapsible = $( ".selector" ).accordion( "option", "collapsible" ); // setter $( ".selector" ).accordion( "option", "collapsible", true ); |
false |
disabled | Boolean | 如果设置为 true ,则禁用该 accordion。代码实例: 初始化带有指定 $( ".selector" ).accordion({ disabled: true }); 在初始化后,获取或设置 // getter var disabled = $( ".selector" ).accordion( "option", "disabled" ); // setter $( ".selector" ).accordion( "option", "disabled", true ); |
false |
event | String | accordion 头部会作出反应的事件,用以激活相关的面板。可以指定多个事件,用空格间隔。 代码实例: 初始化带有指定 $( ".selector" ).accordion({ event: "mouseover" }); 在初始化后,获取或设置 // getter var event = $( ".selector" ).accordion( "option", "event" ); // setter $( ".selector" ).accordion( "option", "event", "mouseover" ); |
"click" |
header | Selector | 标题元素的选择器,通过主要 accordion 元素上的 .find() 进行应用。内容面板必须是紧跟在与其相关的标题后的同级元素。 代码实例: 初始化带有指定 $( ".selector" ).accordion({ header: "h3" }); 在初始化后,获取或设置 // getter var header = $( ".selector" ).accordion( "option", "header" ); // setter $( ".selector" ).accordion( "option", "header", "h3" ); |
"> li > :first-child,> :not(li):even" |
heightStyle | String | 控制 accordion 和每个面板的高度。可能的值:
代码实例: 初始化带有指定 $( ".selector" ).accordion({ heightStyle: "fill" }); 在初始化后,获取或设置 // getter var heightStyle = $( ".selector" ).accordion( "option", "heightStyle" ); // setter $( ".selector" ).accordion( "option", "heightStyle", "fill" ); |
"auto" |
icons | Object | 标题要使用的图标,与 jQuery UI CSS 框架提供的图标(Icons) 匹配。设置为 false 则不显示图标。
代码实例: 初始化带有指定 $( ".selector" ).accordion({ icons: { "header": "ui-icon-plus", "activeHeader": "ui-icon-minus" } }); 在初始化后,获取或设置 // getter var icons = $( ".selector" ).accordion( "option", "icons" ); // setter $( ".selector" ).accordion( "option", "icons", { "header": "ui-icon-plus", "activeHeader": "ui-icon-minus" } ); |
{ "header": "ui-icon-triangle-1-e", "activeHeader": "ui-icon-triangle-1-s" } |
方法 | 返回 | 描述 |
---|---|---|
destroy() | jQuery (plugin only) | 完全移除 accordion 功能。这会把元素返回到它的预初始化状态。
代码实例: 调用 destroy 方法: $( ".selector" ).accordion( "destroy" ); |
disable() | jQuery (plugin only) | 禁用 accordion。
代码实例: 调用 disable 方法: $( ".selector" ).accordion( "disable" ); |
enable() | jQuery (plugin only) | 启用 accordion。
代码实例: 调用 enable 方法: $( ".selector" ).accordion( "enable" ); |
option( optionName ) | Object | 获取当前与指定的 optionName 关联的值。
代码实例: 调用该方法: var isDisabled = $( ".selector" ).accordion( "option", "disabled" ); |
option() | PlainObject | 获取一个包含键/值对的对象,键/值对表示当前 accordion 选项哈希。
代码实例: 调用该方法: var options = $( ".selector" ).accordion( "option" ); |
option( optionName, value ) | jQuery (plugin only) | 设置与指定的 optionName 关联的 accordion 选项的值。
代码实例: 调用该方法: $( ".selector" ).accordion( "option", "disabled", true ); |
option( options ) | jQuery (plugin only) | 为 accordion 设置一个或多个选项。
代码实例: 调用该方法: $( ".selector" ).accordion( "option", { disabled: true } ); |
refresh() | jQuery (plugin only) | 处理任何在 DOM 中直接添加或移除的标题和面板,并重新计算 accordion 的高度。结果取决于内容和 heightStyle 选项。
代码实例: 调用 refresh 方法: $( ".selector" ).accordion( "refresh" ); |
widget() | jQuery | 返回一个包含 accordion 的 jQuery 对象。
代码实例: 调用 widget 方法: var widget = $( ".selector" ).accordion( "widget" ); |
事件 | 类型 | 描述 |
---|---|---|
activate( event, ui ) | accordionactivate | 面板被激活后触发(在动画完成之后)。如果 accordion 之前是折叠的,则 ui.oldHeader 和 ui.oldPanel 将是空的 jQuery 对象。如果 accordion 正在折叠,则 ui.newHeader 和 ui.newPanel 将是空的 jQuery 对象。 注意:由于
代码实例: 初始化带有指定 activate 回调的 accordion: $( ".selector" ).accordion({ activate: function( event, ui ) {} }); 绑定一个事件监听器到 accordionactivate 事件: $( ".selector" ).on( "accordionactivate", function( event, ui ) {} ); |
beforeActivate( event, ui ) | accordionbeforeactivate | 面板被激活前直接触发。可以取消以防止面板被激活。如果 accordion 当前是折叠的,则 ui.oldHeader 和 ui.oldPanel 将是空的 jQuery 对象。如果 accordion 正在折叠,则 ui.newHeader 和 ui.newPanel 将是空的 jQuery 对象。
代码实例: 初始化带有指定 beforeActivate 回调的 accordion: $( ".selector" ).accordion({ beforeActivate: function( event, ui ) {} }); 绑定一个事件监听器到 accordionbeforeactivate 事件: $( ".selector" ).on( "accordionbeforeactivate", function( event, ui ) {} ); |
create( event, ui ) | accordioncreate | 当创建 accordion 时触发。如果 accordion 是折叠的, ui.header 和 ui.panel 将是空的 jQuery 对象。
代码实例: 初始化带有指定 create 回调的 accordion: $( ".selector" ).accordion({ create: function( event, ui ) {} }); 绑定一个事件监听器到 accordioncreate 事件: $( ".selector" ).on( "accordioncreate", function( event, ui ) {} ); |
Examples
A simple jQuery UI accordion (Accordion).
<! Doctype html> <Html lang = "en"> <Head> <Meta charset = "utf-8"> <Title> Folding panel member (Accordion Widget) Demo </ title> <Link rel = "stylesheet" href = "// code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <Script src = "// code.jquery.com/jquery-1.10.2.js"> </ script> <Script src = "// code.jquery.com/ui/1.10.4/jquery-ui.js"> </ script> </ Head> <Body> <Div id = "accordion"> <H3> Part 1 </ h3> <Div> <P> Mauris mauris ante, blandit et, ultrices a, suscipit eget. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. </ P> </ Div> <H3> Part 2 </ h3> <Div> <P> Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor aliquet laoreet, mauris turpis velit, faucibus interdum tellus libero ac justo. </ p> </ Div> <H3> section 3 </ h3> <Div> <P> Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.Phasellus pellentesque purus in massa. </ P> <Ul> <Li> List item one </ li> <Li> List item two </ li> <Li> List item three </ li> </ Ul> </ Div> </ Div> <Script> $ ( "#accordion") .accordion (); </ Script> </ Body> </ Html>