Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

collapsible.js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collapsible.js

A jQuery plugin for creating easy to use collapsible and accordion menus

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Collapsible.js

npm version Bower version

What is it?

Collapsible.js is a lightweight (~1.7kb min) jQuery plugin that was created with the intent to expand on the functionality of the accordion effect found in jQuery UI. Primarily, allow the menu to either be an accordion or expand any/all of the available panels at the same time.

Installation

  • npm: npm install collapsible.js
  • yarn: yarn add collapsible.js
  • Bower: bower install collapsible.js
  • Download latest release

What you need

You'll need jQuery in your project, as well as a script tag referencing the plugin:

<script src="jquery.collapsible.js"></script>

The menu styles can be customized however you would like after that. A stylesheet is included to give a basic example of how they can be customized.

Usage Examples

HTML

For the plugin to function properly, you will need to have your HTML set up in a certain manner. An example of the setup:

<div id="firstCollapseMenu" class="collapse-container">
	<h1><span class="arrow-r"></span>First Heading</h1>
	<div>
		<p>First container paragraph</p>
	</div>
	<h2><span class="arrow-r"></span>Second Heading</h2>
	<div>
		<p>Second container paragraph</p>
	</div>
	<h3><span class="arrow-r"></span>Third Heading</h3>
	<div>
		<p>Third container paragraph</p>
	</div>
</div>
  • The collapse-container class can be named whatever you would like, just remember that it must have the CSS that was mentioned above tied to it.
  • <span class="arrow-r"></span> is used when you would like a triangle (or something similar) in the heading that depicts whether the content is expanded or collapsed. You will need to set up a CSS class for this if you wish to use it. An example class is in the provided CSS stylesheet, otherwise you are welcome to write a custom one.

JavaScript

The simplest way to initialize a collapsible menu:

$('#firstCollapseMenu').collapsible();

There are also several different options that can be set. All of the options and their default values:

$('#firstCollapseMenu').collapsible({
	accordion: false,
	accordionUpSpeed: 400,
	accordionDownSpeed: 400,
	collapseSpeed: 400,
	contentOpen: null,
	arrowRclass: 'arrow-r',
	arrowDclass: 'arrow-d',
	animate: true
});

Explanation of each option:

  • accordion - true if the menu should be an accordion (only 1 panel can be open at a time), false if the menu should be a basic collapsible menu (any number of panels can be open at once).
  • accordionUpSpeed - How fast the closing panel of the accordion is moving (milliseconds).
  • accordionDownSpeed - How fast the opening panel of the accordion is moving (milliseconds).
  • collapseSpeed - How fast the basic collapsible menu panels open/close (milliseconds).
  • contentOpen - Used if you want a panel to be open by default. Index starts at 0. Basic collapsible menus can take an array of numbers. Accordions can also have a panel open by default, but don't take an array.
  • arrowRclass - The CSS class name of the arrow that indicates a panel is closed.
  • arrowDclass - The CSS class name of the arrow that indicates a panel is open.
  • animate - true if the menu should have opening and closing animations. false if there shouldn't be animation, and instead the panels open and close immediately.

No Script

To avoid some potential issues in browsers that do not have JavaScript enabled, adding the follow to your code will allow it to fail more gracefully (the dropdowns will default to being open).

<noscript>
	<style>
		.collapse-container > :nth-child(even) {
			display: block;
		}
	</style>
</noscript>

License

MIT license.

Keywords

FAQs

Package last updated on 01 Jun 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc