You just made an accordion for a client using jQuery UI. Her eyes light up when you show it to her. She tries it out and suddenly the smile changes to a look of confusion.
"Wait, I can only open one at a time?Have you ever been there?
Can you fix that? Also, I want these ones to start closed and these ones to start opened."
startClosedDetermines whether or not the Easy Expand element defaults to a closed state at page load.
- boolean (default = true)
outerContainerDefines the CSS class selector of the Easy Expand outer containers
- string (CSS class name - default: 'outer-container')
buttonContainerDefines the CSS class selector of the Easy Expand button containers
- string (CSS class name - default: 'button-container')
buttonClassSets the CSS class of the Easy Expand arrow toggle buttons.
- string (CSS class name - default: 'easyexpand')
durationSets the duration of the slideToggle() effect in milliseconds.
- INT (default: 200)
easingSets the easing option for the slideToggle()
- string (easing option name - default: 'swing')
NOTE: 'swing' and 'linear' are the only easing methods available by default. Other easing options require the easing plugin.
Using Multiple Options$('.myclass').easyexpand({'option' : 'value', 'option' : 'value'});
Using callbacks
To use a callback function, simply pass the name of the function:
$('.content-container').easyexpand(myCallback);
If you're passing optional settings as well, pass the callback as the second argument.
$('.content-container').easyexpand({'duration' : 250}, myCallback);
In this demo, four of the Easy Expands elements are preset to closed and three others are preset to opened. One Easy Expand element uses a callback to load content dynamically via Ajax.
As you can see below, the key to having multiple Easy Expand elements with differnt settings is to use separate instances of the function, targeting different classes.
$(document).ready(function() {
$('.closed').easyexpand();
$('.open').easyexpand({'startClosed' : false });
$('.callback').easyexpander(myCallback);
function myCallback() {
$('.ajax').load('ajax-content.html');
}
});
Download the Easy Expand jQuery plug-in HERE
$(document).ready(function() {
$('.content-container').easyexpand();
});
<div class="outer-container">
<div class="button-container">
<h2>The header goes here<h2>
<!-- the button goes here --!>
</div>
<div class="content-container">
<p>The content goes here</p>
</div>
</div> <!-- end of .outer-container --!>
Please note:
In this example, we're using the default class names. The div called '.content-container' is the element that will open and close when we click the button. This is where the content goes. This is the specific selector you must target when you call the function. You can use a different class name for this container if you want. However, if you do you must pass it to the function as an optional setting
The '.content-container' needs a sibling div to act as the button container. The button will be automatically generated by easyexpand. The default class for this container is 'button-container.' Again, you can specify your own class name by passing an optional parameter. You can also put a header in this container.
Finally, '.content-container' and '.button-container' both need to be wrapped in a parent div, which is used for DOM traversal. Its default class name is 'outer-container'. As with the other containers, you can specify your own class name.
Please note:
For this demo I've chosen to use CSS 3 rounded corners and CSS 3 gradients as part of the design. Those styles do not work in all browsers. I'm using PIE to enhance browser support for these styles.