Alterna a visibilidade do contido no teu proxecto con algunhas clases e os nosos complementos de JavaScript.
Cómo funciona
O complemento de contraer JavaScript úsase para mostrar e ocultar contido. Os botóns ou áncoras utilízanse como disparadores que se asignan a elementos específicos que alternas. Ao contraer un elemento animarase heightdesde o seu valor actual ata 0. Dado como CSS xestiona as animacións, non se pode usar paddingnun .collapseelemento. En vez diso, use a clase como un elemento de envoltura independente.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
Múltiples obxectivos
A <button>ou <a>pode mostrar e ocultar varios elementos facendo referencia a eles cun selector JQuery no seu atributo hrefou . data-targetMúltiples <button>ou <a>poden mostrar e ocultar un elemento se cada un o fai referencia co seu atributo hrefoudata-target
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
Exemplo de acordeón
Usando o compoñente tarxeta , pode ampliar o comportamento de contraer predeterminado para crear un acordeón. Para lograr correctamente o estilo de acordeón, asegúrate de usalo .accordioncomo envoltorio.
Anímate a reprochar cliché, enim eiusmod high life acusa a Terry Richardson de calamar. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, son aliqua poñer un paxaro sobre el calamar café de orixe única nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur carniceiro vice lomo. Leggings occaecat cervexa artesanal da granxa á mesa, denim cru estética sintetizador nesciunt probablemente non escoitou falar deles accusamus labore sustentable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Accesibilidade
Asegúrese de engadir aria-expandedao elemento de control. Este atributo transmite de forma explícita o estado actual do elemento plegable vinculado ao control aos lectores de pantalla e tecnoloxías auxiliares similares. Se o elemento plegable está pechado por defecto, o atributo do elemento de control debería ter un valor de aria-expanded="false". Se configuraches o elemento plegable para que estea aberto de forma predeterminada usando a showclase, configura aria-expanded="true"o control. O complemento activará automaticamente este atributo no control en función de se se abriu ou non o elemento contraíble (a través de JavaScript ou porque o usuario disparou outro elemento de control tamén vinculado ao mesmo elemento plegable). Se o elemento HTML do elemento de control non é un botón (por exemplo, un <a>ou <div>), o atributorole="button" should be added to the element.
If your control element is targeting a single collapsible element – i.e. the data-target attribute is pointing to an id selector – you should add the aria-controls attribute to the control element, containing the id of the collapsible element. Modern screen readers and similar assistive technologies make use of this attribute to provide users with additional shortcuts to navigate directly to the collapsible element itself.
Note that Bootstrap’s current implementation does not cover the various keyboard interactions described in the WAI-ARIA Authoring Practices 1.1 accordion pattern - you will need to include these yourself with custom JavaScript.
Usage
The collapse plugin utilizes a few classes to handle the heavy lifting:
.collapse hides the content
.collapse.show shows the content
.collapsing is added when the transition starts, and removed when it finishes
These classes can be found in _transitions.scss.
Via data attributes
Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. 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.
To add accordion-like group management to a collapsible area, add the data attribute data-parent="#selector". Refer to the demo to see this in action.
Via JavaScript
Enable manually with:
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
parent
selector | jQuery object | DOM element
false
If parent is provided, then all collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior - this is dependent on the card class). The attribute has to be set on the target collapsible area.
toggle
boolean
true
Toggles the collapsible element on invocation
Methods
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
Activates your content as a collapsible element. Accepts an optional options object.
.collapse('toggle')
Toggles a collapsible element to shown or hidden. Returns to the caller before the collapsible element has actually been shown or hidden (i.e. before the shown.bs.collapse or hidden.bs.collapse event occurs).
.collapse('show')
Shows a collapsible element. Returns to the caller before the collapsible element has actually been shown (i.e. before the shown.bs.collapse event occurs).
.collapse('hide')
Hides a collapsible element. Returns to the caller before the collapsible element has actually been hidden (i.e. before the hidden.bs.collapse event occurs).
.collapse('dispose')
Destroys an element’s collapse.
Events
Bootstrap’s collapse class exposes a few events for hooking into collapse functionality.
Event Type
Description
show.bs.collapse
Este evento desenvólvese inmediatamente cando showse chama ao método de instancia.
mostrado.bs.colapso
Este evento desenvólvese cando un elemento de contraer se fixo visible para o usuario (esperará a que se completen as transicións CSS).
ocultar.bs.colapso
Este evento desenvólvese inmediatamente cando hidese chamou ao método.
oculto.bs.colapso
Este evento desenvólvese cando se ocultou ao usuario un elemento de contraer (esperará a que se completen as transicións CSS).