Socket
Socket
Sign inDemoInstall

accordions

Package Overview
Dependencies
1
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    accordions

ES6 Class to make creating accordions easy, with smooth animation.


Version published
Maintainers
1
Install size
21.6 kB
Created

Readme

Source

Accordions

Accordions is a class which can be used to easily control the opening / closing of accordion content.

Installation

npm i accordions
yarn add accordions

HTML Usage

<section class="[ js-accordion ]">
  <div class="[ js-accordion--item ]">
    <div class="[ js-accordion--trigger ]">Heading Here</div>
    <div class="[ js-accordion--target ]">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ut sodales lectus, ac dictum nibh. Sed commodo auctor leo eu rhoncus. Vivamus tincidunt porttitor leo, ac lacinia augue aliquet at. Nulla convallis, lorem at euismod blandit, odio lectus interdum erat, in ornare eros eros in velit. Fusce auctor ante leo, nec dictum augue efficitur ac. Vestibulum mattis velit eros, vel luctus dui elementum non. Ut leo diam, maximus eu mi eget, suscipit pharetra dolor. Donec laoreet vel ante a sagittis. Nam mattis, arcu id finibus imperdiet, libero metus fringilla dolor, in luctus orci arcu eu sapien. Sed sagittis maximus mi, nec imperdiet odio suscipit at. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Vestibulum posuere ante vestibulum euismod mattis.</p>
    </div>
  </div>
</section>
import Accordion from 'accordions';

const AccordionContent = new Accordion(document.querySelector('.js-accordion'), {
  fps: 60,
  duration: 400,
  multiple: false,
});
OptionTypeDescriptionDefault
fpsnumberthe number of frames per second that we animate the content60
durationnumbernumber in milliseconds that the content will open or close in400
multiplebooleanif false opening an item will close the othersfalse
Adding Accordion Items
AccordionContent.add(element, {
  active: false,
  minHeight: 0,
  trigger: element.firstElementChild,
  target: element.lastElementChild,
});

The add method will load the accordion with a new item. the tween() method takes 2 arguments. The first argument is the element containing the accordion content. The second argument is the user options

OptionTypeDescriptionDefaults
activebooleanIf true the item will be open on page loadfalse
minHeightnumberJust in case you dont want the accordion to close all the way0
triggerelementThe element that we will click on to open the accordion itemthe accordion item element's first child
targetelementThe element that we will open and close to reveal some contentthe accordion item element's last child

License

MIT

Keywords

FAQs

Last updated on 17 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc