Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fgm/accordion

A tiny VanillaJS accordion library
https://github.com/fgm/accordion

accordion vanilla-javascript vanilla-js

Last synced: 9 days ago
JSON representation

A tiny VanillaJS accordion library

Awesome Lists containing this project

README

        

# accordion

A tiny VanillaJS Accordion library.

Should work on all current 2020 browsers.

## Usage

- Prepare your markup as a plain HTML Definition List with class `accordion`.
- Link your version of `accordion.css` to it, adjusting as needed.
- Load `domready.js` and `accordion.js` in your page, or use your own `DOMready`
library
- Instantiate the accordion as:

```ecmascript 6
domReady(() => {
const el = new WofAccordion(window);
if (!el.isValid) {
return;
}
window.wofAccordion = el; // Optional: convenient for debug.
});
```

Only a single Accordion will work on any given page.

## Markup

Accordion uses a smaller set of classes than its previous versions.

The expected structure is a plain HTML Definition List with class `accordion`:


pane header

pane item

pane item


...

...



At most one item may have the `accordion-active` class at the same time, and
should not contain a link, as it represents the current page.

## Changes

- New version uses vanilla JS, no longer depending on jQuery.
- New version is 4 times smaller the the jQuery version, not even counting jQuery
itself.