07/03
2012
dev-master
9999999-devSmall jQuery plugin that collapses a box on a toggle
MIT
jquery
Wallogit.com
2017 © Pedro PelĂĄez
Small jQuery plugin that collapses a box on a toggle
Sébastien Lavoie (sebastien@lavoie.sl), (*1)
Simple solution to a common problem:, (*2)
Much can be done, but this is the first version, (*3)
<div class="collapse-wrapper">
<div class="header">
<a href="#" class="collapse-toggle">Toggle</a>
</div>
<div class="collapse-box">
<ul>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</div>
</div>
$(function() {
$('.collapse-wrapper').autoCollapser();
});
{
box: '.collapse-box', // The box that will be collasped
toggle: '.collapse-toggle', // The trigger, binding will be added onClick
collapsedClass: 'collapse-collapsed', // Class to be added to the wrapper when it is collapsed
expandedClass: 'collapse-expanded', // Idem
duration: 800, // Speed in ms for the animation,
stop: true // Empty the queue using .stop(true, true)
}
.collapse-wrapper {
border: 1px solid green;
padding: 10px;
margin: 10px;
}
.collapse-expanded .collapse-toggle::after {
content: " -"
}
.collapse-collapsed .collapse-toggle::after {
content: " +"
}
.collapse-box {
border: 1px solid red;
margin: 10px;
}
$('.collapse-wrapper').autoCollapser('show');
$('.collapse-wrapper').autoCollapser('hide');
$('.collapse-wrapper').autoCollapser('toggle');
````
### Events
Two events are made and they both pass the data.show as a boolean
* autoCollapser.toggle.start
* autoCollapser.toggle.after
```javascript
$('.collapse-wrapper').on('autoCollapser.toggle.start', function(event,data){
console.log("Collapser has started " + (data.show ? 'expanding' : 'collasping'));
});
$('.collapse-wrapper').on('autoCollapser.toggle.after', function(event,data){
console.log("Collapser was " + (data.show ? 'expanded' : 'collasped'));
});
Checkout the demo, (*4)
Small jQuery plugin that collapses a box on a toggle
MIT
jquery