百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

Accordion

> 编程语言
开源

JavaScript 的轻量级、易于使用的折叠模块。非常有用,可在您的网站上创建常见问题列表。

398 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

JavaScript 的轻量级、易于使用的折叠模块。非常有用,可在您的网站上创建常见问题列表。

Accordion

Lightweight and accessible accordion module with an extensible API. With the module you can create accordion on your website, useful especially for creating FAQ lists.

Version

3.4.1

Installation

npm

Install the package & import files

bash
npm install accordion-js
javascript
import Accordion from "accordion-js";
import "accordion-js/dist/accordion.min.css";
CDN

Include files using CDN.

https://unpkg.com/[email protected]/dist/accordion.min.css
https://unpkg.com/[email protected]/dist/accordion.min.js
xml
Github

You can also download files from Github and attach them manually to your project.

Note: On production use files (JS and CSS) only from dist/ folder.

Usage

Include files

See the section above.

Create HTML layout

This is just an example of a layout. You can create your own HTML structure.

xml

  

  

  

  

  
Initialize the module
xml

API

Examples

new Accordion(container, options)

  • container - string | HTMLElement | Array (required), A selector string, a DOM element, or an array of selector strings or HTMLElements that specify the accordion container(s).
  • options - object (optional), Configuration options for the accordion. See the table below for available options.
…
Options
Option Type Default value Description
duration number 500 Animation duration in ms
ariaEnabled boolean true Add ARIA elements to the HTML structure
collapse boolean true Allow collapse expanded panel
showMultiple boolean false Show multiple elements at the same time
onlyChildNodes boolean true Disabling this option will find all items in the container. Warning: Setting to false will break the functionality of nested accordions
openOnInit array [] Show accordion elements during initialization
elementClass string "ac" Element class
triggerClass string "ac-trigger" Trigger class
panelClass string "ac-panel" Panel class
activeClass string "is-active" Active element class
beforeOpen function - Calls before the item is opened.
beforeOpen: (currElement) => {}
onOpen function - Calls when the item is opened.
onOpen: (currElement) => {}
beforeClose function - Calls before the item is closed.
beforeClose: (currElement) => {}
onClose function - Calls when the item is closed.
onClose: (currElement) => {}
Methods
Option Description Arguments
attachEvents() Attach events -
detachEvents() Detach events -
open() Open the accordion element with the given idx
E.g. acc.open(1) idx - element index
close() Close the accordion element with the given idx
E.g. acc.close(1) idx - element index
toggle() Toggle the accordion element with the given idx
E.g. acc.toggle(1) idx - element index
openAll() Open all accordion elements (without animation) -
closeAll() Close all accordion elements (without animation) -
update() If there are new items added by lazy load, you can run this method to update the Accordion -
destroy() Destroy accordion instance:
Open elements, remove events, IDs & ARIA -

v3 Release Info

There have been a lot of changes to the API in version 3.0.0, so if you are using previous versions of the accordion (2.8.0 and below), I recommend updating the package to the latest version with new structure and options.

License

This project is under the MIT license.

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScripta11yaccessibilityaccordionaria

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言