Preklopite vidnost vsebine v vašem projektu z nekaj razredi in našimi vtičniki JavaScript.
Kako deluje
Vtičnik JavaScript za strnitev se uporablja za prikaz in skrivanje vsebine. Gumbi ali sidra se uporabljajo kot sprožilci, ki so preslikani na določene elemente, ki jih preklapljate. Strnjenje elementa bo animiralo heightiz trenutne vrednosti v 0. Glede na to, kako CSS obravnava animacije, ne morete uporabiti paddingna .collapseelementu. Namesto tega uporabite razred kot neodvisen ovojni element.
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.
Več ciljev
A <button>ali <a>lahko prikaže in skrije več elementov tako, da se nanje sklicuje z izbirnikom JQuery v svojem atributu hrefali . data-targetVeč <button>ali <a>lahko prikaže in skrije element, če se vsak sklicuje nanj s svojim hrefali data-targetatributom
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.
Primer harmonike
S komponento kartice lahko razširite privzeto vedenje strnjevanja, da ustvarite harmoniko. Da bi pravilno dosegli slog harmonike, se prepričajte, da uporabite .accordionkot ovoj.
Animacija pariatnega klišeja, ki ga je preprečevala, eiusmod high life obtožba terry richardson in lignji. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Tovornjak s hrano kvinoja nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it lignji kava z enim poreklom nulla acceptenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Oglas veganski razen mesarja vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt verjetno še niste slišali zanje acusamus 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.
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.
Dostopnost
Bodite prepričani, da dodate aria-expandedv kontrolni element. Ta atribut izrecno posreduje trenutno stanje zložljivega elementa, povezanega s kontrolnikom, bralnikom zaslona in podobnim pomožnim tehnologijam. Če je zložljivi element privzeto zaprt, mora imeti atribut na nadzornem elementu vrednost aria-expanded="false". showČe ste z razredom nastavili, da je zložljivi element privzeto odprt, ga aria-expanded="true"namesto tega nastavite na kontrolniku. Vtičnik bo samodejno preklopil ta atribut na kontrolniku glede na to, ali je bil zložljivi element odprt ali zaprt (prek JavaScripta ali ker je uporabnik sprožil drug kontrolni element, prav tako povezan z istim elementom collapbile). Če element HTML kontrolnika ni gumb (npr. <a>ali <div>), atributrole="button"je treba dodati elementu.
Če vaš kontrolni element cilja na en sam zložljiv element – tj. data-targetatribut kaže na idizbirnik – dodajte aria-controlsatribut v kontrolni element, ki vsebuje idelement zložljivega elementa. Sodobni bralniki zaslona in podobne podporne tehnologije uporabljajo ta atribut, da uporabnikom zagotovijo dodatne bližnjice za navigacijo neposredno do samega zložljivega elementa.
Upoštevajte, da trenutna izvedba Bootstrapa ne pokriva različnih interakcij s tipkovnico, opisanih v vzorcu harmonike WAI-ARIA Authoring Practices 1.1 – te boste morali vključiti sami s prilagojenim JavaScriptom.
Uporaba
Vtičnik Collapse uporablja nekaj razredov za obvladovanje težkega dvigovanja:
.collapseskriva vsebino
.collapse.showprikazuje vsebino
.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
Ta dogodek se sproži takoj, ko showse pokliče metoda primerka.
prikazano.bs.zruši
Ta dogodek se sproži, ko je element strnjenja viden uporabniku (počakal bo, da se prehodi CSS zaključijo).
hide.bs.collapse
Ta dogodek se sproži takoj, ko hideje bila metoda poklicana.
hidden.bs.collapse
Ta dogodek se sproži, ko je bil strnjeni element skrit pred uporabnikom (počakal bo, da se zaključijo prehodi CSS).