Code Monkey home page Code Monkey logo

accordion-plugin's Introduction

Accordion

A simple and lightweight JavaScript library for accordion

Peculiarities

  • No dependencies. The library is written in pure JavaScript and does not require any other libraries to work.
  • Simplicity and functionality. You can easily and quickly connect and use a library that implements important functionality for the accordion
  • Availability. The accordion meets all accessibility rules.
  • Customization with CSS. You can easily change the appearance, layout using CSS.

How to work with the library

  1. Download the latest version of the library
  2. Connect accordion.min.css and accordion.min.js from the dist folder to the page
  3. Place the following markup in your HTML document:
<ul class="accordion" data-acordion="accordion">
  <li class="accordion__item">
    <button class="accordion__button">button</button>
    <div class="accordion__collapse">
      <div class="accordion__content">
        <div class="accordion__body">
          Lorem ipsum dolor sit amet
        </div>
      </div>
    </div>
  </li>
  <li class="accordion__item">
    <button class="accordion__button">button</button>
    <div class="accordion__collapse">
      <div class="accordion__content">
        <div class="accordion__body">
          Lorem ipsum dolor sit amet
        </div>
      </div>
    </div>
  </li>
  <li class="accordion__item">
    <button class="accordion__button">button</button>
    <div class="accordion__collapse">
      <div class="accordion__content">
        <div class="accordion__body">
          Lorem ipsum dolor sit amet
        </div>
      </div>
    </div>
  </li>
</ul>

Important nuance

You can create positioning styles only for the child element accordion__content, for example for accordion__body

  1. margin
  2. padding
  3. position and so on
<ul class="accordion" data-acordion="accordion">
	<li class="accordion__item">
    <button class="accordion__button">button</button>
    <div class="accordion__collapse">
      <div class="accordion__content">
        <div class="accordion__body">
          You can create positioning styles for the accordion__body element
        </div>
      </div>
    </div>
  </li>
</ul>  

data-accordion - an important data attribute through which all interaction with the plugin works. The value of this attribute must be unique to the page.

  1. Place the following JS code to connect the accordion:
const accordion = new Accordion('accordion');

The library supports two parameters:

  1. params speed: 1000 - affects the speed of the accordion
  2. params turn: true - affects the operation of the accordion
const accordion = new Accordion('accordion', {
	speed: 1000,
  turn: true
});

You can see an example of how the library works by opening the index.html file from the demo folder in the browser.

Enjoy!

accordion-plugin's People

Contributors

vahanhovanisyan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.