Giter VIP home page Giter VIP logo

jquery-accordion's Introduction

jQuery Accordion

Responsive, CSS powered, jQuery accordion plugin.

Jquery Accordion uses CSS transitions to animate opening/closing with a fallback to jQuery's animate when CSS transitions are not supported. It takes little configuration or code to use it on your project. Try out the demo.

Supports IE9+ and modern browsers.

Developed by @vctrfrnndz. Licensed under the MIT License.

Usage

$('.accordion').accordion({
    "transitionSpeed": 400
});

Options

Name Default Type Description
transitionSpeed 300 int Transition speed on miliseconds.
transitionEasing 'ease' string CSS value for easing.
controlElement '[data-control]' string CSS selector for the element acting as a button.
contentElement '[data-content]' string CSS selector for the element containing hide/show content.
groupElement '[data-accordion-group]' string CSS selector for a parent element containing a group.
singleOpen true boolean Opens a single accordion a time.

Events

accordion.open fires when any accordion opens

accordion.close fires when any accordion closes

accordion.toggle toggles accordion open/close when triggered on a controlElement. This will not be triggered if it affects more than one accordion while singleOpenis enabled.

accordion.refresh manually refreshes the height of an accordion. Useful when adding elements to the accordion dynamically.

Sample Structure

For a simple accordion/dropdown, use the following structure/data-attributes:

<div data-accordion>
    <div data-control>Control</div>
    <div data-content>
        <div>Row</div>
        <div>Row</div>
        <div>Row</div>
    </div>
</div>

For a group of accordions, you can use the data-accordion-group attribute on a parent, this will allow you to activate/deactivate the single open behavior by setting singleOpen to true/false.

<div data-accordion-group>
    <div class="accordion" data-accordion>
        <div data-control>Control</div>
        <div data-content>
            <div>Row</div>
            <div>Row</div>
            <div>Row</div>
        </div>
    </div>
    <div class="accordion" data-accordion>
        <div data-control>Control</div>
        <div data-content>
            <div>Row</div>
            <div>Row</div>
            <div>Row</div>
        </div>
    </div>
</div>

Starting with opened state

To initialize the accordion with an open state just add the class .open to your accordion element.

<div data-accordion-group>
    <div class="accordion open" data-accordion>
        <div data-control>Control</div>
        <div data-content>
            <div>Row</div>
            <div>Row</div>
            <div>Row</div>
        </div>
    </div>
</div>

jquery-accordion's People

Contributors

bryanerwin avatar mladimatija avatar passy avatar vctrfrnndz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-accordion's Issues

feature request: 'data-opened' to start opened

Is there an option to start some accordion panel in opened state?

I tried to achieve this using some:

<article data-accordion class="open">

in the source html (I'm using singleOpen:false)

But it gives issues if i do that: it's like the height isn't calculated well in this case and i get the accordion trigger title nodes disappearing after their first close event

Do you plan to support some sort of data-start-opened attribute in multi-open mode too?

Initialization of opened branch of multilevel list

Hi,
Thank you for this smart script for accordion. I tried to implement it with opened only one defined branch of closed tree - by class="accordion open" defined in parent elements (in demo) - and there is some problem with calculating height.
It seems that script calculate only height of first parent element and ignore others inside.

<section id="only-one" data-accordion-group> <section class="accordion open" data-accordion> <button data-control>Accordion 1</button> <div data-content> <article>Item</article> <article class="accordion open" data-accordion> <button data-control>2nd Level</button>

image

I tried to figure out and but withou success.

Does anybody have any idea?

Accordion sections displayed above all the sections?

Is it possible for the accordion nav/triggers and their content sections displayed separately? I would like to display all choices in a horizontal list above all the content areas.

Very similar to traditional tabbed content. I'm already using this script extensively throughout the site and trying to avoid adding yet another library into the mix for this one area.

Thanks.

Events on example page

Hi,
Can you use on the example the events? I am trying to use them and they are not working for me.

Thanks!

Events on open and close

It would be nice to have some events triggered when when any accordion is opened closed. Could be used for showing state changes, etc. I have created a branch that has a basic example.

Print styling

Hi there! Really love the simplicity of this plugin. It works great.

I am sorting out my print style sheets and can't get the content inside the accordion to show by default. The inline styling is taking precedence over everything, including the !important declaration.

Here is my CSS showing my print styles and then the inline style above it.

image

Any ideas on how to disable the accordion in print view?

Accessibility

We should add aria attributes to make the accordions accessible. AFAIK these are ones we should add on to the control element:

  • aria-expanded
  • aria-disabled
  • role
  • aria-controls (this is the only tricky one. we need to provide a selector for the content element here.)

An these on the content element:

  • aria-hidden

Non-Linear Toggles for Accordions

Hello,

Currently, the Toggle button triggers the accordion that immediately follows that toggle button like:

Toggle


Accordion

Is there a way to create a accordion whose trigger is placed somewhere else on the page like so:

Toggle


Text, Image


Accordion

Thanks
Vilav

Trigger on mobile breakpoints only

I love your work! I am using it on a site where the accordion should only show on mobile devices.

Is there a way to tell the javascript to fire on a certain breakpoint?

If not, I'm glad to work on this and submit a pull request. Any suggestions on how you prefer this to happen would help as well.

Releases

Hello,

It would be nice to have tagged releases so it is easier to use this plugin with Bower.

Regards,

Not working when JS is disabled

When I disable JS, using a chrome extension, the accordion can no longer expand or collapse. Isn’t this supposed to be CSS powered and not rely on JS?

Some people use script blocking extensions on their browser so it would be great if the accordion was still functional(or at least had the nodes auto expanded) when this happens.

toggling a single accordion causes form to submit.

Within a signup form, I have the terms of service in an accordion. When I click on the accordion, it triggers the signup form to be submitted. The submit button for the form is just below the accordion, but there is ample space so it is not touched. Have you encountered this before?

Manually recalculate height

Is there a way to manually recalculate the height of the accordion panel? If you dynamically add an element into the panel, it stays the same height and parts of the elements become obscured.

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.