Bootstrap 4 JS Recolher
Recolher classes CSS
Para um tutorial sobre Colapsíveis, leia nosso Tutorial de Colapso do Bootstrap .
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 dados-* Atributos
Basta adicionar data-toggle="collapse"
e um data-target
elemento to para atribuir automaticamente o controle de um elemento dobrável. O atributo data-target aceita um seletor CSS ao qual aplicar o recolhimento. Certifique-se de adicionar o recolhimento de classe ao elemento recolhível. Se você quiser que ele seja aberto por padrão, adicione a classe adicional "show".
Exemplo
<button class="btn" data-toggle="collapse" data-target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Some text..
</div>
Dica: Para adicionar gerenciamento de grupo do tipo acordeão a um controle recolhível, adicione o atributo de dados data-parent="#selector".
Por JavaScript
Ative manualmente com:
$('.collapse').collapse()
Opções de recolhimento
As opções podem ser passadas por meio de atributos de dados ou JavaScript. Para atributos de dados, anexe o nome da opção a data-, como em 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 |
Métodos de recolhimento
A tabela a seguir lista todos os métodos de recolhimento disponíveis.
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 |
Recolher eventos
A tabela a seguir lista todos os eventos de recolhimento disponíveis.
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) |