Basic Responsive Accordion In Vanilla JavaScript – Accordionjs

Category: Accordion , Javascript | May 25, 2017
Author: simondavies
Views Total: 2,019
Official Page: Go to website
Last Update: May 25, 2017
License: MIT

Preview:

Basic Responsive Accordion In Vanilla JavaScript – Accordionjs

Description:

A simple, lightweight, Vanilla JavaScript library for creating a responsive accordion interface where the users are able to expand or collapse the content by clicking on the associated panel headers.

How to use it:

Load the minified version of the Accordionjs’s JS & CSS files in your document.

<link rel="stylesheet" href="accordionjs.min.css">
<script src="accordionjs.min.js" defer></script>

Create the accordion panels & headers as follows:

<div id="the-accordion" class="accordion-wrapper">

  <div class="accordion-panel">
    <div class="accordion-title"><a href="#">Question A</a>
    </div>
    <div class="accordion-content">
      <p>Answer A</p>
    </div>
  </div>

  <div class="accordion-panel">
    <div class="accordion-title"><a href="#">Question B</a>
    </div>
    <div class="accordion-content">
      <p>Answer B</p>
    </div>
  </div>

  <div class="accordion-panel">
    <div class="accordion-title"><a href="#">Question C</a>
    </div>
    <div class="accordion-content">
      <p>Answer C</p>
    </div>
  </div>

</div>

Create a new accordion instance and done.

new AccordionJS();

Assign a different id value to the ‘AccordionJS()’ function, so you can run two or more accordions on one page.

new AccordionJS('the-accordion-two');

Leave a Reply