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

https://github.com/stefangabos/zebra_accordion

A lightweight, customizable, and cross-browser jQuery accordion plugin - 3KB minified (1.3KB gzipped) with easy configuration options
https://github.com/stefangabos/zebra_accordion

accordion accordion-jquery-plugin accordion-plugin accordion-widget collapse collapsible

Last synced: about 1 month ago
JSON representation

A lightweight, customizable, and cross-browser jQuery accordion plugin - 3KB minified (1.3KB gzipped) with easy configuration options

Awesome Lists containing this project

README

        

zebrajs

# Zebra Accordion  [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=A+tiny,+easily+configurable,+fully+customizable,+cross-browser+jQuery+accordion+plugin&url=https://github.com/stefangabos/Zebra_Accordion&via=stefangabos&hashtags=jquery,javascript)

*A lightweight, customizable, and cross-browser jQuery accordion plugin - 3KB minified (1.3KB gzipped) with easy configuration options*

[![npm](https://img.shields.io/npm/v/zebra_accordion.svg)](https://www.npmjs.com/package/zebra_accordion) [![Total](https://img.shields.io/npm/dt/zebra_accordion.svg)](https://www.npmjs.com/package/zebra_accordion) [![Monthly](https://img.shields.io/npm/dm/zebra_accordion.svg)](https://www.npmjs.com/package/zebra_accordion) [![](https://data.jsdelivr.com/v1/package/npm/zebra_accordion/badge?style=rounded)](https://www.jsdelivr.com/package/npm/zebra_accordion) [![License](https://img.shields.io/npm/l/zebra_accordion.svg)](https://github.com/stefangabos/Zebra_Accordion/blob/master/LICENSE.md)

Zebra Accordion is a lightweight, user-friendly jQuery plugin designed for creating smooth, interactive accordion menus. Its compact size (3KB minified) ensures your web projects remain fast and responsive. The plugin's extensive customization options allow developers to easily modify animations, durations, and other behavior for a tailored user experience. With cross-browser support and simple implementation, Zebra_Accordion is an excellent choice for building collapsible content sections, FAQs, and sidebars that enhance usability without compromising performance.

## Key features of this jQuery accordion plugin

- no additional markup required other than a basic definition list
- no default style allowing you to fully customize it to suit your needs
- works with responsive layouts
- allows for a single expanded tab at a time, or for any number of tabs to be expanded/collapsed
- allows for tabs to expand on mouse over, not just on click
- if an expanded tab's content is not in the viewport it automatically scrolls the browser window so that the content is visible
- callback functions can be used for further customizations
- works in pretty much any browser - Firefox, Chrome, Safari, Edge, Opera and Internet Explorer 6+

## 🎂 Support the development of this project

Your support means a lot and it keeps me motivated to keep working on open source projects.

If you like this project please ⭐ it by clicking on the star button at the top of the page.

If you are feeling generous, you can buy me a coffee by donating through PayPal, or you can become a sponsor.

Either way - **Thank you!** 🎉

[Star it on GitHub](https://github.com/stefangabos/Zebra_Accordion) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NBM9XKB7XAB5L) [](https://github.com/sponsors/stefangabos)

## Demo

See the [demos](https://stefangabos.github.io/Zebra_Accordion/)

## Requirements

Zebra Accordion has no dependencies other than jQuery 1.7.0+

## Installation

Zebra Accordion is available as a [npm package](https://www.npmjs.com/package/zebra_accordion). To install it use:

```bash
# the "--save" argument adds the plugin as a dependency in packages.json
npm install zebra_accordion --save
```

## How to use

First, load jQuery from a CDN and provide a fallback to a local source like:

```html

window.jQuery || document.write('<script src="path/to/jquery-3.5.0.js"><\/script>')
```

Load the Zebra Accordion jQuery plugin:

```html

```

Alternatively, you can load Zebra Accordion from [JSDelivr CDN](https://www.jsdelivr.com/package/npm/zebra_accordion) like this:

```html

```

Load the style sheet file from a local source

```html

```

...or from [JSDelivr CDN](https://www.jsdelivr.com/package/npm/zebra_accordion)

```html

```

You need a basic definition list for your HTML markup

> Don't forget to add the `Zebra Accordion` class to the list container! If you'll [have a look](https://github.com/stefangabos/Zebra_Accordion/blob/master/dist/zebra_accordion.css) you will see that all it does is to set `display:hidden` the all the tabs and add `cursor:pointer` to titles, so it will not add overweight to your CSS and that you will have to style the accordion to suit your needs.

```html


Lorem ipsum dolor sit amet consectetuer


Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et.
Quis hendrerit neque congue pretium iaculis justo laoreet orci elit condimentum.
Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

Lorem ipsum dolor sit amet consectetuer


Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et.
Quis hendrerit neque congue pretium iaculis justo laoreet orci elit condimentum.
Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

Lorem ipsum dolor sit amet consectetuer


Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et.
Quis hendrerit neque congue pretium iaculis justo laoreet orci elit condimentum.
Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

Lorem ipsum dolor sit amet consectetuer


Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et.
Quis hendrerit neque congue pretium iaculis justo laoreet orci elit condimentum.
Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.


```

Now, within the DOM-ready event do

```javascript
$(document).ready(function() {

new $.Zebra_Accordion($('.Zebra_Accordion'));

});
```

## Configuration options

## Properties



Property
Type
Default
Description




animate_opacity
boolean
true
Should a tab's opacity be also animated when expanding/collapsing?


collapsible
mixed
false

- when set to true it indicates that all tabs can be collapsed


- if set to false, an expanded tab can be collapsed only by expanding another tab


- if set to 0, the behavior is the same when set to false with the difference that an open tab can also be closed.



expanded_class
string
Zebra_Accordion_Expanded

The name of the class to append to an expanded tab's associated title element.


Use it to customize the aspect of expanded tabs.



hide_speed
integer
400

The speed (in milliseconds) to use when collapsing a tab.



scroll_speed
integer
600

If an tab's content is not entirely visible once it is expanded, the browser window will be scrolled so that the entire content is visible (if it is possible).


This value represents the speed (in milliseconds) used for scrolling browser window to the right position.



show_speed
integer
400

The speed (in milliseconds) to use when expanding a tab.



show
mixed
0

The index (0 based) of the tab to be expanded by default.


The value of this property can also be boolean FALSE, indicating that all tabs should be collapsed by default.


If the value of the collapsible property is TRUE, the value of this property can also be boolean TRUE, indicating that all tabs should be expanded by default. In this case, you can also provide an array of indexes to be expanded by default.



toggle_on_mouseover
boolean
false

Set this to TRUE if tabs should be expanded when hovering the mouse over their associated titles.


If the collapsible property is true, this property will always be considered as false!



## Events



Event
Description




onBeforeClose

Event fired before a tab is collapsed

The callback function takes 3 arguments:


  • the tab's position in the accordion (0 based)

  • the associated title element, as a jQuery object

  • the tab, as a jQuery object





onBeforeOpen

Event fired before a tab is expanded

The callback function takes 3 arguments:

  • the tab's position in the accordion (0 based)

  • the associated title element, as a jQuery object

  • the tab, as a jQuery object





onClose

Event fired after a tab is collapsed

The callback function takes 3 arguments:

  • the tab's position in the accordion (0 based)

  • the associated title element, as a jQuery object

  • the tab, as a jQuery object





onOpen

Event fired after a tab is collapsed

The callback function takes 3 arguments:

  • the tab's position in the accordion (0 based)

  • the associated title element, as a jQuery object

  • the tab, as a jQuery object




## Methods

### `show(index, [noFx = FALSE], [noScroll = FALSE])`

Expands a tab.

#### Arguments

`index` - the 0-based index of the tab to expand

`noFx` - *(optional)* - if set to TRUE, the tab will be instantly expanded without animation.

Default is false.

`noScroll` - *(optional)* - if set to TRUE, the browser window will not be scrolled to the newly expanded tab.

Default is false.

```javascript
var myAccordion = new $.Zebra_Accordion($('#accordion'));

// expand the third tab
myAccordion.show(2);
```

### `hide(index, [noFx = FALSE])`

Expands a tab.

#### Arguments

`index` - the 0-based index of the tab to collapse

`noFx` - *(optional)* - if set to TRUE, the tab will be instantly collapsed without animation.

Default is false.

```javascript
var myAccordion = new $.Zebra_Accordion($('#accordion'));

// collapse the first tab
myAccordion.hide(0);
```

## Sponsors

Cross browser/device testing is done with

[![BrowserStack](https://github.com/stefangabos/Zebra_Dialog/raw/master/examples/browserstack.png)](https://www.browserstack.com/)