Bootstrap 4 JS Collapse

Collapse CSS Classes

For a tutorial about Collapsibles, read our Bootstrap Collapse Tutorial.

ClassDescriptionExample
.collapseHides the contentTry it
.collapse showShows the collapsible content by defaultTry it
.collapsingAdded when the transition starts, and removed when it finishesTry it

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>
Try it Yourself »
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="".
NameTypeDefaultDescriptionTry it
parentselectorfalseAll collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior)Try it
togglebooleantrueToggles the collapsible element on invocationTry it

Collapse Methods

The following table lists all available collapse methods.
MethodDescriptionTry it
.collapse(options)Activates the collapsible element with an option. See options above for valid values
.collapse("toggle")Toggles the collapsible elementTry it
.collapse("show")Shows the collapsible elementTry it
.collapse("hide")Hides the collapsible elementTry it
.collapse("dispose")Destroys the collapsible element

Collapse Events

The following table lists all available collapse events.
EventDescriptionTry it
show.bs.collapseOccurs when the collapsible element is about to be shownTry it
shown.bs.collapseOccurs when the collapsible element is fully shown (after CSS transitions have completed)Try it
hide.bs.collapseOccurs when the collapsible element is about to be hiddenTry it
hidden.bs.collapseOccurs when the collapsible element is fully hidden (after CSS transitions have completed)Try it


Credit: www.w3schools.com
Bootstrap 4 JS Collapse Bootstrap 4 JS Collapse Reviewed by webmission on 11:17 Rating: 5

No comments:

Powered by Blogger.