Web Development with jQuery (2015)
Part IV. Appendices
Appendix N. Accordion
Method |
Description |
Return Value |
Showing and Hiding Methods |
||
accordion(options) |
Makes the selected elements into accordions (see “Accordion Options”). |
jQuery |
accordion('destroy') |
Destroys the selected accordion. |
jQuery |
accordion('disable') |
Disables the selected accordion. |
jQuery |
accordion('enable') |
Enables the selected accordion. |
jQuery |
accordion('option') |
Returns an object containing all the options and their values. |
Object |
accordion('refresh') |
Recalculates accordion panels, headers, and heights after modifying an accordion. |
jQuery |
accordion('widget') |
Returns a jQuery object that contains the accordion. |
jQuery |
Accordion Options |
||
Option |
Description |
Type |
active |
Determines which panel is open, if any. If the value is set to false, all panels are collapsed. (This requires the collapsible option to be set true. If the value is set to an integer, it opens the corresponding panel, offset from zero.) |
Boolean, Integer |
animate |
Options for animating the panels. Setting the value to false disables animation. Setting the value to a number sets the length of the animation in milliseconds with the easing effect. If the value is a string, the string is the type of easing animation (see Appendix M, “Effects”). An object can also be provided with easing and duration properties. |
Boolean, Number, String, Object |
collapsible |
Whether all the accordion sections can be closed at once. |
Boolean |
disabled |
Whether the accordion is disabled. |
Boolean |
event |
The event used to trigger the accordion. |
String |
header |
Selector referencing the element to use for the header element for each content panel. |
Selector, Element, jQuery |
heightStyle |
Determines how the height of each panel is calculated. |
String |
icons |
Icons to use for headers. |
Object |
Accordion Events |
||
activate |
Triggered once a panel is activated (after the animation has finished). |
function (event, ui) |
beforeActivate |
Triggered once a panel is opened, before animation begins. Can be canceled to prevent a panel from activating. |
function (event, ui) |
create |
Triggered when an accordion is created. |
function (event, ui) |
Accordion UI Object Options
The callback functions specified for various accordion events specify a ui object in the second argument. Following are the properties exposed in the ui object.
Option |
Description |
Type |
ui.header |
The active header. |
jQuery |
ui.newHeader |
The header of the panel about to be activated. |
jQuery |
ui.newPanel |
The panel about to be activated. |
jQuery |
ui.oldHeader |
The header of the panel about to be deactivated. |
jQuery |
ui.oldPanel |
The panel about to be deactivated. |
jQuery |
ui.panel |
The active panel. |
jQuery |