Silky-smooth accordion widgets with no external dependencies.
npm install accordion --save
bower install silk-accordion --save
Include the following two files in your project:
src/accordion.css
src/accordion.js
Layout your markup like this:
<div class="accordion">
<div>
<h1> Heading </h1>
<div> Content </div>
</div>
<div>
<h1> Heading </h1>
<div> Content </div>
</div>
</div>
Then create an Accordion
instance with a reference to a DOM element:
var el = document.querySelector(".accordion");
new Accordion(el);
Options can be passed in a second argument:
new Accordion(el, {
onToggle: function(fold, isOpen){
console.log(fold); // -> Reference to a `Fold` instance
console.log(isOpen); // -> true / false
}
});
Name | Type | Default | Description |
---|---|---|---|
closeClass | String | "closed" |
CSS class used to mark a fold as closed |
disabled | Boolean | false |
Whether to disable the accordion on creation |
disabledClass | String | undefined |
CSS class marking an accordion as disabled |
edgeClass | String | "edge-visible" |
CSS class toggled based on whether the bottom-edge is visible |
enabledClass | String | "accordion" |
CSS class marking an accordion as enabled |
heightOffset | Number | 0 |
Distance to offset each fold by |
noAria | Boolean | false |
Disable the addition and management of ARIA attributes |
noKeys | Boolean | false |
Disable keyboard navigation |
noTransforms | Boolean | false |
Disable CSS transforms; positioning will be used instead |
onToggle | Function | undefined |
Callback executed when opening or closing a fold |
openClass | String | "open" |
CSS class controlling each fold's "open" state |
snapClass | String | "snap" |
CSS class for disabling transitions between window resizes |
useBorders | Boolean | "auto" |
Consider borders when calculating fold heights |
Different distribution flavours are available in the dist
directory:
- amd: For RequireJS
- common-js: For NodeJS-like ecosystems
- es6: For Babel, or whenever ES6 becomes universally supported by browsers.
- raw: Compressed and uncompressed ES5 versions, the latter of which is also available in
src
.
The base stylesheet is located at src/accordion.css
.
Feel free to embed it into your application's existing styling, tweaking it if desired.