Giter VIP home page Giter VIP logo

accordion's Introduction

Accordion

Silky-smooth accordion widgets with no external dependencies.

npm install accordion --save
bower install silk-accordion --save

Usage

Include the following two files in your project:

src/accordion.css
src/accordion.js

Layout your markup like this:

<div class="accordion">

	<div>
		<h1> Heading </h1>
		<div> Content </div>
	</div>
	
	<div>
		<h1> Heading </h1>
		<div> Content </div>
	</div>
	
</div>

Then create an Accordion instance with a reference to a DOM element:

var el = document.querySelector(".accordion");
new Accordion(el);

Options can be passed in a second argument:

new Accordion(el, {
    onToggle: function(fold, isOpen){
        console.log(fold);   // -> Reference to a `Fold` instance
        console.log(isOpen); // -> true / false
    }
});

Options

Name Type Default Description
closeClass String "closed" CSS class used to mark a fold as closed
disabled Boolean false Whether to disable the accordion on creation
disabledClass String undefined CSS class marking an accordion as disabled
edgeClass String "edge-visible" CSS class toggled based on whether the bottom-edge is visible
enabledClass String "accordion" CSS class marking an accordion as enabled
heightOffset Number 0 Distance to offset each fold by
noAria Boolean false Disable the addition and management of ARIA attributes
noKeys Boolean false Disable keyboard navigation
noTransforms Boolean false Disable CSS transforms; positioning will be used instead
onToggle Function undefined Callback executed when opening or closing a fold
openClass String "open" CSS class controlling each fold's "open" state
snapClass String "snap" CSS class for disabling transitions between window resizes
useBorders Boolean "auto" Consider borders when calculating fold heights

Modular use

Different distribution flavours are available in the dist directory:

  • amd: For RequireJS
  • common-js: For NodeJS-like ecosystems
  • es6: For Babel, or whenever ES6 becomes universally supported by browsers.
  • raw: Compressed and uncompressed ES5 versions, the latter of which is also available in src.

The base stylesheet is located at src/accordion.css. Feel free to embed it into your application's existing styling, tweaking it if desired.

accordion's People

Contributors

alhadis avatar

Watchers

 avatar

Forkers

rice-hiroko

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.