Giter Club home page Giter Club logo

collapsible's Introduction

Collapsible.js Bower

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

##What you need You'll need jQuery in your project, as well as a reference to the plugin:

<script type="text/javascript" src="jquery.collapsible.js"></script>

The only other thing you'll need so that the menu(s) display properly is the display : none; CSS property:

.collapse-container>:nth-child(even) {
	display : none;
}

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.

License

MIT license.

collapsible's People

Contributors

claudiojs avatar jordnkr avatar

Watchers

 avatar  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.