Collapse CSS Classes
For a tutorial about Collapsibles, read our Bootstrap Collapse Tutorial.
Class | Description | Example |
---|---|---|
.collapse | Hides the content | |
.collapse show | Shows the collapsible content by default | |
.collapsing | Added when the transition starts, and removed when it finishes |
Via data-* Attributes
Just add
data-toggle="collapse"
and a data-target
to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class "show".Example
<button class="btn" data-toggle="collapse" data-target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Some text..
</div>
Tip: To add accordion-like group management to a collapsible control, add the data attribute data-parent="#selector".
Via JavaScript
Enable manually with:
$('.collapse').collapse()
Collapse Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-parent="".
Name | Type | Default | Description | Try it |
---|---|---|---|---|
parent | selector | false | All collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior) | |
toggle | boolean | true | Toggles the collapsible element on invocation |
Collapse Methods
The following table lists all available collapse methods.
Method | Description | Try it |
---|---|---|
.collapse(options) | Activates the collapsible element with an option. See options above for valid values | |
.collapse("toggle") | Toggles the collapsible element | |
.collapse("show") | Shows the collapsible element | |
.collapse("hide") | Hides the collapsible element | |
.collapse("dispose") | Destroys the collapsible element |
Collapse Events
The following table lists all available collapse events.
Event | Description | Try it |
---|---|---|
show.bs.collapse | Occurs when the collapsible element is about to be shown | |
shown.bs.collapse | Occurs when the collapsible element is fully shown (after CSS transitions have completed) | |
hide.bs.collapse | Occurs when the collapsible element is about to be hidden | |
hidden.bs.collapse | Occurs when the collapsible element is fully hidden (after CSS transitions have completed) |
Credit: www.w3schools.com
Bootstrap 4 JS Collapse
Reviewed by webmission
on
11:17
Rating:
No comments:
Post a Comment