Kokwea
Toggle visibilité ya contenus na kati ya projet na yo na mua ba classes na ba plugins na biso ya JavaScript.
Ndenge oyo esalaka
Plugin ya JavaScript ya kokweya esalelamaka mpo na kolakisa mpe kobomba makambo oyo ezali na kati. Ba boutons to ba ancres esalelamaka lokola ba déclencheur oyo e mapé na ba éléments spécifiques oyo o toggler. Ko collapser élément moko eko animer la height
depuis valeur na yango ya lelo na 0
. Soki totali ndenge CSS esimbaka ba animations, okoki te kosalela padding
na .collapse
élément moko. Na esika ya kosala bongo, salelá kelasi lokola eloko ya kokanga oyo ezali na boyokani te.
prefers-reduced-motion
requête ya média. Tala
eteni ya mouvement réduit ya mikanda na biso ya accessibilité .
Ndakisa
Finá na ba boutons oyo ezali awa na nse mpo na kolakisa mpe kobomba eloko mosusu na nzela ya mbongwana ya kelasi:
.collapse
ebombaka makambo oyo ezali na kati.collapsing
esalelamaka na ntango ya mbongwana.collapse.show
elakisaka makambo oyo ezali na kati
En général, tosengi kosalela bouton oyo ezali na data-bs-target
attribut. Atako esengami te na point de vue sémantique, okoki mpe kosalela lien na href
attribut (mpe a role="button"
). Na makambo nyonso mibale, data-bs-toggle="collapse"
esɛngami.
<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-bs-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
Ya kolala
Plugin ya collapse esalisaka pe collapse horizontale. Bakisa .collapse-horizontal
kelasi ya modificateur mpo na kosala transition ya na width
esika ya height
mpe kotya a width
na élément ya mwana ya mbala moko. Bozala na bonsomi ya kokoma Sass na bino moko oyo olingi, kosalela ba styles ya inline, to kosalela ba utilitaires na biso ya largeur .
min-height
ensemble mpo na koboya kozongisa langi mingi na ba docs na biso, yango esengeli te polele.
Kaka width
élément oyo ezali na mwana nde esengeli.
<p>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseWidthExample" aria-expanded="false" aria-controls="collapseWidthExample">
Toggle width collapse
</button>
</p>
<div style="min-height: 120px;">
<div class="collapse collapse-horizontal" id="collapseWidthExample">
<div class="card card-body" style="width: 300px;">
This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
</div>
</div>
</div>
Ba cibles ebele
A <button>
to <a>
ekoki kolakisa mpe kobomba ba éléments ebele na kosala référence na yango na selecteur na attribut na yango href
to . data-bs-target
Multiple <button>
to <a>
bakoki kolakisa mpe kobomba élément moko soki bango moko na moko azali kosala référence na yango na attribut na bango href
todata-bs-target
<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1">Toggle first element</a>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">Toggle second element</button>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target=".multi-collapse" aria-expanded="false" aria-controls="multiCollapseExample1 multiCollapseExample2">Toggle both elements</button>
</p>
<div class="row">
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample1">
<div class="card card-body">
Some placeholder content for the first collapse component of this multi-collapse example. This panel is hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
</div>
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample2">
<div class="card card-body">
Some placeholder content for the second collapse component of this multi-collapse example. This panel is hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
</div>
</div>
Kozala na makoki ya kozwa yango
Bozala sûr ya kobakisa aria-expanded
na élément ya contrôle. Attribut oyo ezo transmettre explicitement état actuel ya élément collapsible lié na contrôle na ba lecteurs d'écran na ba technologies d'assistance ya ndenge wana. Soki élément collapsible ekangami na ndenge ya défaut, attribut na élément ya contrôle esengeli kozala na valeur ya aria-expanded="false"
. Soki otie élément collapsible ezala ouvert par défaut kosalela show
classe, tia aria-expanded="true"
na contrôle na esika na yango. Plugin eko changer automatiquement attribut oyo na contrôle selon soki to te élément collapsible efungolami to ekangami (na nzela ya JavaScript, to mpo mosaleli a déclenché élément mosusu ya contrôle mpe ekangami na même élément collapsible). Soki élément HTML ya élément ya contrôle ezali bouton te (ndakisa, an <a>
to <div>
), attributrole="button"
esengeli kobakisa yango na elemande yango.
Soki élément ya contrôle na yo ezali ko cibler élément moko collapsible – c’est-à-dire data-bs-target
attribut ezali ko pointer id
sélecteur moko – esengeli obakisa aria-controls
attribut na élément de contrôle, oyo ezali na id
ya élément collapsible. Ba lecteurs d’écran ya mikolo oyo mpe ba technologies ya assistance ya ndenge wana esalelaka attribut oyo mpo na kopesa ba usagers ba raccourcis ya kobakisa mpo na ko naviguer directement na élément collapsible yango moko.
Yeba ete bosaleli ya Bootstrap ya lelo etali te ba interactions ya clavier optionnel ndenge na ndenge oyo elimbolami na modèle ya accordéon ya WAI-ARIA Authoring Practices 1.1 - ekosenga otia yo moko oyo na JavaScript personnalisé.
Sass oyo azali
Ba variables oyo ezali
$transition-collapse: height .35s ease;
$transition-collapse-width: width .35s ease;
Bakelasi
Ba classes ya transition ya collapse ekoki kozwama na scss/_transitions.scss
lokola oyo ekabolami na kati ya ba composants ebele (collapse na accordéon).
.collapse {
&:not(.show) {
display: none;
}
}
.collapsing {
height: 0;
overflow: hidden;
@include transition($transition-collapse);
&.collapse-horizontal {
width: 0;
height: auto;
@include transition($transition-collapse-width);
}
}
Kosalela yango
Plugin ya collapse esalelaka mua ba classes pona ko gérer levage ya kilo:
.collapse
ebombaka makambo oyo ezali na kati.collapse.show
elakisaka makambo oyo ezali na kati.collapsing
ebakisami ntango mbongwana ebandi, mpe elongolami ntango esili
Bakelasi yango ekoki kozwama na _transitions.scss
.
Na nzela ya ba attributs ya ba données
Bobakisa kaka data-bs-toggle="collapse"
mpe a data-bs-target
na élément mpo na ko assigner automatiquement contrôle ya élément moko to ebele oyo ekoki ko collapsible. Attribut data-bs-target
endimi moponi ya CSS mpo na kosalela collapse na yango. Bozala sûr ya kobakisa classe collapse
na élément collapsible. Soki olingi ete efungwama na ndenge ya liboso, bakisá kelasi ya kobakisa show
.
Mpo na kobakisa boyangeli ya etuluku lokola accordéon na esika oyo ekoki kokangama, bakisa attribut ya ba données data-bs-parent="#selector"
. Talá lokasa ya accordéon mpo na koyeba makambo mosusu.
Na nzela ya JavaScript
Activer manuellement na:
var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
var collapseList = collapseElementList.map(function (collapseEl) {
return new bootstrap.Collapse(collapseEl)
})
Makambo oyo okoki kopona
Ba options ekoki koleka na nzela ya ba attributs ya ba données to JavaScript. Mpo na ba attributs ya ba données, bakisa kombo ya option na data-bs-
, lokola na data-bs-parent=""
.
Nkombo | Lolenge | Mbeba | Ndimbola |
---|---|---|---|
parent |
moponi | jEloko ya motuna | Elemento DOM | false |
Soki moboti epesami, boye biloko nyonso oyo ekoki kokangama na nse ya moboti oyo elakisami ekokangama ntango eloko oyo ekoki kokangama ekolakisama. (ekokani na bizaleli ya bonkoko ya accordéon - yango etali card kelasi). Attribut esengeli ezala na esika oyo ekoki kokangama na cible. |
toggle |
boolean | true |
Ebalusaka élément collapsible na invocation |
Ba méthodes ya kosala
Ba méthodes asynchrones na ba transitions
Ba méthodes nionso ya API ezali asynchrone mpe ebandi transition . Bazongaka epai ya moto oyo abengi ntango kaka mbongwana ebandi kasi liboso ete esila . En plus, appel ya méthode na composante ya transition ekozala ignorée .
Tala mikanda na biso ya JavaScript mpo na koyeba makambo mosusu .
Active contenus na yo lokola élément collapsible. Andimi ba options moko ya option object
.
Okoki kosala instance ya collapse na constructeur, ndakisa:
var myCollapse = document.getElementById('myCollapse')
var bsCollapse = new bootstrap.Collapse(myCollapse, {
toggle: false
})
Metode | Ndimbola |
---|---|
toggle |
Ezali kobongola eloko oyo ekoki kokangama mpo na kolakisa to kobombama. Ezongi na mobengi yambo ete eloko oyo ekoki kokangama ezala mpenza kolakisa to ebombama (elingi koloba liboso ete likambo shown.bs.collapse to hidden.bs.collapse esalema). |
show |
Ezali kolakisa eleman moko oyo ekoki kokangama. Ezongisaka na mobengi yambo ete eloko oyo ekoki kokangama elakisama mpenza (ndakisa, yambo ete shown.bs.collapse likambo esalema). |
hide |
Ebombaka eloko moko oyo ekoki kokangama. Ezongi na mobengi yambo ete eloko oyo ekoki kokangama ebombama mpenza (ndakisa, yambo ete hidden.bs.collapse likambo esalema). |
dispose |
Ebebisaka collapse ya élément moko. (Elongolaka ba données oyo ebombami na élément DOM) |
getInstance |
Méthode statique oyo e permettre yo ozua instance ya collapse associé na élément DOM, okoki kosalela yango boye:bootstrap.Collapse.getInstance(element) |
getOrCreateInstance |
Méthode statique oyo ezongisaka instance ya collapse oyo ezo sangana na élément DOM to ezo sala ya sika au cas où ezalaki initialisé te. Okoki kosalela yango boye:bootstrap.Collapse.getOrCreateInstance(element) |
Makambo oyo esalemaki
Classe ya collapse ya Bootstrap e exposer mua ba événements pona ko crochet na fonctionnalité ya collapse.
Lolenge ya likambo | Ndimbola |
---|---|
show.bs.collapse |
Evenement oyo ezo beta mbala moko tango show méthode ya instance ebengami. |
shown.bs.collapse |
Evenement oyo ezo beta tango élément ya collapse esalemi visible na mosaleli (ekozela ba transitions ya CSS esila). |
hide.bs.collapse |
Evenement oyo ebetamaka mbala moko tango hide méthode ebengami. |
hidden.bs.collapse |
Evenement oyo ezo beta tango élément ya collapse ebombami na mosaleli (ekozela ba transitions ya CSS esila). |
var myCollapsible = document.getElementById('myCollapsible')
myCollapsible.addEventListener('hidden.bs.collapse', function () {
// do something...
})