Fɔdɔm
Toggle di visibiliti fɔ kɔntinyu akɔdin to yu prɔjek wit sɔm klas dɛn ɛn wi JavaSkript plɔgin dɛn.
Klik di bɔtin dɛn we de dɔŋ fɔ sho ɛn ayd ɔda ɛlimɛnt bay we dɛn chenj di klas:
.collapse
de ayd di tin dɛn we de insay.collapsing
na di tɛm we dɛn de chenj.collapse.show
sho wetin de insay
Yu kin yuz wan link wit di href
atribyut, ɔ wan bɔtin wit di data-target
atribyut. Insay dɛn tu kes ya, data-toggle="collapse"
dɛn nid fɔ du di.
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
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.
</div>
</div>
A <button>
ɔ <a>
kin sho ɛn ayd bɔku ɛlimɛnt dɛn bay we i de rɛfrɛns dɛn wit wan JQuery sɛlɛktɔ na in href
ɔ data-target
atribyut. Bɔku <button>
ɔ <a>
kin sho ɛn ayd wan ɛlimɛnt if dɛn ɔl de rɛfrɛns am wit dɛn href
ɔ data-target
atribyut
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1">Toggle first element</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">Toggle second element</button>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-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">
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.
</div>
</div>
</div>
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample2">
<div class="card card-body">
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.
</div>
</div>
</div>
</div>
Yuz di kad kɔmpɔnɛnt, yu kin ɛkstɛnd di difɔlt kɔllaps bihayvya fɔ mek wan akodiɔn.
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
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.
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
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.
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Collapsible Group Item #3
</button>
</h5>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">
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.
</div>
</div>
</div>
</div>
Mek shɔ se yu ad aria-expanded
pan di kɔntrol ɛlimɛnt. Dis atribyut de sho klia wan di stet we di kollapsbul ɛlimɛnt tay to di kɔntrol to skrin rida ɛn di sem kayn ɛp tɛnkɔlɔji dɛn. If di kollapsbul ɛlimɛnt klos bay difɔlt, di atribyut na di kɔntrol ɛlimɛnt fɔ gɛt valyu fɔ aria-expanded="false"
. If yu dɔn sɛt di kollapsibl ɛlimɛnt fɔ opin bay difɔlt yuz di show
klas, sɛt aria-expanded="true"
pan di kɔntrol insted. Di plɔgin go ɔtomɛtik tɔgl dis atribyut na di kɔntrol bay we dɛn dɔn opin ɔ lɔk di kɔlapsibl ɛlimɛnt ɔ nɔ dɔn opin (via JavaSkript, ɔ bikɔs di yuza trig ɔda kɔntrol ɛlimɛnt we dɛn tay bak to di sem kɔlapsbayl ɛlimɛnt). If di kɔntrol ɛlimɛnt in HTML ɛlimɛnt nɔto bɔtin (ɛgz., wan <a>
ɔ <div>
), di atribyutrole="button"
fɔ ad to di ɛlimɛnt.
If yu kɔntrol ɛlimɛnt de tɔch wan singl kɔlapsibl ɛlimɛnt – dat na di data-target
atribyut de pɔynt to wan id
sɛlɛktɔ – yu fɔ ad di aria-controls
atribyut to di kɔntrol ɛlimɛnt, we gɛt di id
ɔf di kɔlapsibl ɛlimɛnt. Di mɔdan skrin rida dɛn ɛn di sem kayn ɛp tɛnkɔlɔji dɛn de yuz dis atribyut fɔ gi di wan dɛn we de yuz am ɔda sɔtkat dɛn fɔ go dairekt to di ɛlimɛnt sɛf we dɛn kin kol.
Notis se di implimɛnt we Bootstrap de du naw nɔ de kɔba di difrɛn kibɔd intarakshɔn dɛn we dɛn tɔk bɔt na di WAI-ARIA Ɔtorin Praktis 1.1 akodiɔn patɛn - yu go nid fɔ put dɛn wan ya yusɛf wit kɔstɔm JavaSkript.
Di kollaps plɔgin de yuz sɔm klas dɛn fɔ handel di ebi liftin:
.collapse
de ayd di tin dɛn we de insay.collapse.show
sho di tin dɛn we de insay.collapsing
dɛn kin ad am we di chenj bigin, ɛn dɛn kin pul am we i dɔn
Yu kin fɛn dɛn klas ya na _transitions.scss
.
Jɔs ad data-toggle="collapse"
ɛn a data-target
to di ɛlimɛnt fɔ ɔtomɛtik asaynd kɔntrol fɔ wan ɔ mɔ ɛlimɛnt dɛn we kin kol. Di data-target
atribyut de aksept wan CSS sɛlɛktɔ fɔ aplay di kɔlapshɔn to. Mek shɔ se yu ad di klas collapse
to di ɛlimɛnt we yu kin kɔlap. If yu want fɔ mek i opin difɔlt, ad di ɔda klas show
.
Fɔ ad grup manejmɛnt we tan lɛk akɔdiɔn to wan eria we pɔsin kin kɔlap, ad di data atribyut data-parent="#selector"
. Rif to di demo fɔ si dis in akshɔn.
Enable manually wit:
Yu kin pas opshɔn dɛn bay we yu yuz data atribyut ɔ JavaSkript. Fɔ data atribyut dɛn, ad di opshɔn nem to data-
, lɛk insay data-parent=""
.
Nem | Kayn | Balans | Tɔk bɔt |
---|---|---|---|
mama ɔ papa | sɛlɛktɔ | jKwɛri ɔbjɛkt | DOM elemɛnt | lay | If dɛn gi mama ɔ papa, den ɔl di ɛlimɛnt dɛn we dɛn kin kɔl ɔnda di mama ɔ papa we dɛn dɔn spɛsifa go lɔk we dɛn sho dis tin we pɔsin kin kɔl. (similar to tradishonal akכdiכn bihayvya - dis de dipכnt pan di card klas). Di atribyut gɛt fɔ sɛt na di target kɔllapsibl eria. |
fɔ chenj di we aw dɛn de | boolean we dɛn kɔl | tru | Toggles di kollapsibl elemɛnt pan invokeshɔn |
Asynchronous mεtכd dεm εn transishכn dεm
Ɔl di API mɛtɔd dɛn na asynchronous ɛn dɛn kin stat wan transishɔn . Dɛn kin go bak to di pɔsin we kɔl am jɔs lɛk aw dɛn bigin fɔ chenj bɔt bifo i dɔn . Apat frɔm dat, dɛn go ignore wan mɛtɔd kɔl pan wan transishɔn kɔmpɔnɛnt .
Aktiv yu kɔntinyu as wan ɛlimɛnt we pɔsin kin kɔlap. Aksept wan opshɔnal opshɔn dɛn object
.
Toggles wan kollapsibl elemɛnt fɔ sho ɔ ayd. Ritɔn to di pɔsin we kɔl bifo di kɔlapsibl ɛlimɛnt dɔn rili sho ɔ ayd (dat na bifo di shown.bs.collapse
ɔ hidden.bs.collapse
ivin apin).
Sho wan ɛlimɛnt we pɔsin kin kɔlap. Ritɔn to di pɔsin we kɔl bifo di kɔlapsibl ɛlimɛnt dɔn rili sho (dat na bifo di shown.bs.collapse
ivin apin).
I de ayd wan ɛlimɛnt we pɔsin kin kɔlap. Ritɔn to di pɔsin we kɔl bifo di kɔlapsibl ɛlimɛnt dɔn rili ayd (dat na bifo di hidden.bs.collapse
ivin apin).
Destroy wan element in kollaps.
Bootstrap in kollaps klas de ɛksplɔz sɔm ivintɛns fɔ huk insay kollaps funkshɔnaliti.
Di kayn tin we apin | Tɔk bɔt |
---|---|
sho.bs.kɔlaps | Dis ivent de faya wantɛm wantɛm we dɛn kɔl di show instans mɛtɔd. |
sho.bs.kɔlaps | Dis ivent de faya we dɛn dɔn mek wan kollaps ɛlimɛnt fɔ si to di yuza (go wet fɔ CSS transishɔn dɛn fɔ dɔn). |
ayd.bs.kollaps fɔ di wan dɛn we de | Dis ivent de faya wantɛm wantɛm we hide dɛn dɔn kɔl di we aw dɛn de du am. |
ayd.bs.kɔlaps | Dis ivent de faya we dɛn dɔn ayd wan kollaps ɛlimɛnt frɔm di yuza (go wet fɔ CSS transishɔn dɛn fɔ dɔn). |