Bootstrap 4 JS Zwiń
Zwiń klasy CSS
Aby zapoznać się z samouczkiem dotyczącym zwijanych, zapoznaj się z samouczkiem Bootstrap Collapse .
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 |
Przez dane-* Atrybuty
Wystarczy dodać data-toggle="collapse"
i data-target
element, aby automatycznie przypisać kontrolę nad zwijanym elementem. Atrybut data-target akceptuje selektor CSS, do którego ma zostać zastosowane zwinięcie. Pamiętaj, aby dodać zwinięcie klasy do zwijanego elementu. Jeśli chcesz, aby była domyślnie otwarta, dodaj dodatkową klasę „pokaż”.
Przykład
<button class="btn" data-toggle="collapse" data-target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Some text..
</div>
Wskazówka: aby dodać zarządzanie grupami podobne do akordeonu do zwijanej kontrolki, dodaj atrybut danych data-parent="#selector".
Przez JavaScript
Włącz ręcznie za pomocą:
$('.collapse').collapse()
Opcje zwijania
Opcje można przekazywać za pomocą atrybutów danych lub JavaScript. W przypadku atrybutów danych dołącz nazwę opcji do data-, jak w 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 |
Metody zwijania
W poniższej tabeli wymieniono wszystkie dostępne metody zwijania.
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 |
Zwiń wydarzenia
W poniższej tabeli wymieniono wszystkie dostępne zdarzenia zwijania.
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) |