This example simply sets a class attribute to the details and let's an external stylesheet toggle the collapsed state.
Hello Sir.
I'm sliding
jQuery Collapse
1. Include the Javascript jquery.collapse.js
at the bottom of the web page.
<script src="path/to/jquery.collapse.js"></script>
2. There are no CSS file included within this plugin for default styling, so you can use demo.css
file from demo
folder or styling yourself as per the project requirements. Also you can use the CSS from below.
.jq-accordion{ margin: 0; padding: 0;}
.jq-accordion h3{ margin: 0; padding: 0 0 0 20px; background: #9c9fff; color: #FFF; margin-top: 2px; position: relative;}
.jq-accordion h3::after{ content: '\f105'; font-family: FontAwesome; position: absolute; left: 20px; top: 7px; display: inline-block;}
.jq-accordion h3 a{ color: #FFF; padding: 8px 20px; display: block;}
.jq-accordion h3.open::after{ transform: rotate(90deg);}
.jq-content{ background: #FFF; padding: 25px;}
3. Add the basic HTML to the page and we're ready to go.
<div class="jq-accordion" data-collapse="accordion">
<h3 class="open">Fruits</h3>
<div class="jq-content">
<ul>
<li>Apple</li>
<li>Pear</li>
<li>Orange</li>
</ul>
</div>
<h3>Info</h3>
<div class="jq-content">
<p>You can use any container you like (in this case a div element)</p>
</div>
</div>
$("#demo").collapse({
// options...
});
Name | Default/Useage | Type | Description |
---|---|---|---|
open |
|
function | Custom function for opening section |
close |
|
function | Custom function for collapsing section |
accordion |
false | Boolean | Enable accordion behaviour by setting this option to 'true' |
persist |
false | Boolean | Enable persistence between page loads by setting this option to 'true' |
query |
string | ||
clickQuery |
string |
Example usage of options:
// Initializing collapse plugin
// with custom open/close methods,
// persistence plugin and accordion behaviour
$("#demo").collapse({
open: function() {
// The context of 'this' is applied to
// the collapsed details in a jQuery wrapper
this.slideDown(100);
},
close: function() {
this.slideUp(100);
},
accordion: true,
persist: true
});
$("#demo").bind("opened", function(e, section) {
console.log(section, " was opened");
});
$("#demo").bind("closed", function(e, section) {
console.log(section, " was closed");
});
$("#demo").trigger("open") // open all sections
$("#demo").trigger("close") // close all sections
$("#demo h2 a").last().trigger("toggle") // toggle last section
var demo = new jQueryCollapse($("#demo")); // Initializing plugin
demo.open(); // Open all sections
demo.close(); // Close all sections
demo.open(0); // Open first section
demo.open(1); // Open second section
demo.close(0); // Close first section
demo.toggle(1); // Toggle second section
You can use any container you like (in this case a div element)
<div class="jq-accordion" data-collapse>
<h3>Fruits</h3>
<div class="jq-content">
<ul>
<li>Apple</li>
<li>Pear</li>
<li>Orange</li>
</ul>
</div>
<h3>Info</h3>
<div class="jq-content">
<p>You can use any container you like (in this case a div element)</p>
</div>
</div>
** No additional script is required. For basic styling please add the CSS from the post page.
You can use any container you like (in this case a div element)
<div class="jq-accordion" data-collapse="accordion">
<h3 class="open">Fruits</h3>
<div class="jq-content">
<ul>
<li>Apple</li>
<li>Pear</li>
<li>Orange</li>
</ul>
</div>
<h3>Info</h3>
<div class="jq-content">
<p>You can use any container you like (in this case a div element)</p>
</div>
</div>
** No additional script is required. For basic styling please add the CSS from the post page.
This example simply sets a class attribute to the details and let's an external stylesheet toggle the collapsed state.
Hello Sir.
I'm sliding
This example simply sets a class attribute to the details and let's an external stylesheet toggle the collapsed state.
Hello Sir.
This example simply sets a class attribute to the details and let's an external stylesheet toggle the collapsed state.
<div class="jq-accordion" id="css3-animated-example">
<h3>Hello</h3>
<div class="jq-content">
<div class="content">
<p>This example simply sets a class attribute to the details and let's an
external stylesheet toggle the collapsed state.</p>
<p>Hello Sir.</p>
<p>I'm sliding</p>
</div>
</div>
<h3>Friend</h3>
<div class="jq-content">
<div class="content">
<p>This example simply sets a class attribute to the details and let's an
external stylesheet toggle the collapsed state.</p>
<p>Hello Sir.</p>
</div>
</div>
<h3>Foe</h3>
<div class="jq-content">
<div class="content">
<p>This example simply sets a class attribute to the details and let's an
external stylesheet toggle the collapsed state.</p>
</div>
</div>
</div>
$("#css3-animated-example").collapse({
accordion: true,
open: function() {
this.addClass("open");
this.css({ height: this.children().outerHeight() });
},
close: function() {
this.css({ height: "0px" });
this.removeClass("open");
}
});
#css3-animated-example h3 + div{ display: block!important; height: 0px; padding: 0px; overflow: hidden; transition: all 0.3s ease;}
#css3-animated-example .content{ padding: 25px;}