Collapse
Shandura kuoneka kwezviri mukati meprojekiti yako nemakirasi mashoma uye yedu JavaScript plugins.
Zvinoshanda sei
Iyo yekuputsika JavaScript plugin inoshandiswa kuratidza nekuviga zvirimo. Mabhatani kana zvibatiso zvinoshandiswa sezvinokonzeresa zvakamisikidzwa kune chaiwo zvinhu zvaunoshandura. Kupeta chinhu kuno raramisa height
kubva pakukosha kwayo kuenda ku 0
. Tichifunga kuti CSS inobata sei mifananidzo, haugone kushandisa padding
pane .collapse
chinhu. Pane kudaro, shandisa kirasi sechinhu chakazvimirira chekuputira chinhu.
prefers-reduced-motion
nemubvunzo wenhau. Ona chikamu
chakaderedzwa chezvinyorwa zvedu zvekusvikika .
Muenzaniso
Dzvanya mabhatani ari pazasi kuratidza uye kuviga chimwe chinhu kuburikidza nekuchinja kwekirasi:
.collapse
anovanza zviri mukati.collapsing
inoshandiswa panguva yekuchinja.collapse.show
inoratidza zvirimo
Kazhinji, tinokurudzira kushandisa bhatani rine data-bs-target
hunhu. Kunyange zvisingakurudzirwe kubva pakuona semantic, unogona zvakare kushandisa chinongedzo chine href
hunhu (uye a role="button"
). Muzviitiko zvose izvi, data-bs-toggle="collapse"
zvinodiwa.
<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>
Horizontal
Iyo yekudonha plugin zvakare inotsigira yakachinjika kudonha. Wedzera iyo .collapse-horizontal
modifier kirasi kuti uchinje iyo width
pachinzvimbo height
uye isa width
pane yezvino mwana chinhu. Inzwa wakasununguka kunyora yako wega tsika Sass, shandisa inline masitaera, kana kushandisa yedu yehupamhi zvishandiso .
min-height
seti yekudzivirira yakawandisa repaint mumagwaro edu, izvi hazvidiwe zvakajeka.
Chete width
pane chinhu chemwana chinodiwa.
<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>
Zvinangwa zvakawanda
A <button>
kana <a>
inogona kuratidza uye kuvanza zvinhu zvakawanda nekuzvirevera neanosarudza mune ayo href
kana data-bs-target
hunhu. Yakawanda <button>
kana <a>
inogona kuratidza uye kuvanza chinhu kana mumwe nemumwe akachinongedzera nechavo href
kana data-bs-target
hunhu
<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>
Accessibility
Iva nechokwadi chekuwedzera aria-expanded
kune chekutonga chinhu. Uhwu hunhu hunoburitsa zviripachena mamiriro azvino echinhu chinokorokoka chakasungirirwa pakutonga kuvaverengi vezvikirini uye mamwe matekinoroji ekubatsira. Kana iyo chinhu chinoputika chakavharwa nekusagadzika, hunhu huri pane chekutonga hunofanirwa kuve nehukoshi hwe aria-expanded="false"
. Kana iwe wakaseta chinhu chinoputika kuti chivhurwe nekusarudzika uchishandisa show
kirasi, isa aria-expanded="true"
pane control pane. Iyo plugin inozochinja otomatiki hunhu uhu pahutongi zvichibva pakuti kana chinhu chinokorokoka chavhurwa kana kuvharwa (kuburikidza neJavaScript, kana nekuti mushandisi akonzeresa chimwe chinhu chekudzora chakasungirirwa kune chimwe chinhu chinoputika). Kana iyo control element's HTML element isiri bhatani (semuenzaniso, an <a>
kana <div>
), hunhurole="button"
inofanira kuwedzerwa kune element.
Kana chinhu chako chekutonga chiri kunanga chinhu chimwe chinoputsika - kureva kuti data-bs-target
hunhu huri kunongedza kune imwe id
sarudzo - iwe unofanirwa kuwedzera aria-controls
hunhu kuchinhu chekutonga, chine id
chechinhu chinodonha. Vaverengi vemazuva ano skrini uye matekinoroji ekubatsira akafanana anoshandisa hunhu uhwu kupa vashandisi mamwe mapfupi ekufamba akananga kuchinhu chinoputika pachacho.
Ziva kuti kuita kwazvino kweBootstrap hakuvharidzire kupindirana kwakasiyana-siyana kwekiibhodhi kunotsanangurwa muWAI-ARIA Maitiro eVanyori 1.1 accordion pateni - unozofanirwa kusanganisa iwe pachako neJavaScript.
Sass
Variables
$transition-collapse: height .35s ease;
$transition-collapse-width: width .35s ease;
Makirasi
Kupunza makirasi eshanduko anogona kuwanikwa mukati scss/_transitions.scss
sezvo aya akagovaniswa muzvikamu zvakawanda (kudonha uye accordion).
.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);
}
}
Usage
Iyo yekudonha plugin inoshandisa mashoma makirasi kubata inorema kusimudza:
.collapse
inovanza zviri mukati.collapse.show
inoratidza zviri mukati.collapsing
inowedzerwa kana shanduko yatanga, uye inobviswa kana yapera
Aya makirasi anogona kuwanikwa mu _transitions.scss
.
Via data hunhu
Ingo wedzera data-bs-toggle="collapse"
uye a data-bs-target
kune chinhu kuti ugozvigadzike kutonga kwechimwe kana kupfuura chinodonha zvinhu. Hunhu data-bs-target
hunogamuchira CSS selector yekushandisa iyo kuputsika. Iva nechokwadi chekuwedzera kirasi collapse
kune chinhu chinoputika. Kana uchida kuti risavhurika, wedzera imwe kirasi show
.
Kuwedzera accordion-senge boka manejimendi munzvimbo inoputsika, wedzera iyo data hunhu data-bs-parent="#selector"
. Tarisa kune accordion peji kuti uwane rumwe ruzivo.
Via JavaScript
Vhura nemaoko ne:
var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
var collapseList = collapseElementList.map(function (collapseEl) {
return new bootstrap.Collapse(collapseEl)
})
Options
Sarudzo dzinogona kupfuudzwa kuburikidza nedata hunhu kana JavaScript. Nezve data hunhu, wedzera iyo sarudzo zita ku data-bs-
, semu data-bs-parent=""
.
Zita | Type | Default | Tsanangudzo |
---|---|---|---|
parent |
selector | jQuery chinhu | DOM chikamu | false |
Kana mubereki apihwa, zvese zvinopeta pasi pemubereki wataurwa zvichavharwa kana chinhu chinopetana ichi charatidzwa. (zvakafanana nemaitiro echinyakare accordion - izvi zvinoenderana card nekirasi). Hunhu hunofanirwa kuiswa panzvimbo inoputsika. |
toggle |
boolean | true |
Inoshandura chinhu chinopeta pakukumbira |
Nzira
Asynchronous nzira uye shanduko
Yese nzira dzeAPI dzine asynchronous uye dzinotanga shanduko . Vanodzokera kumunhu anenge afona pachangotanga shanduko asi isati yapera . Pamusoro pezvo, kufona kwenzira pachikamu chekuchinja kuchafuratirwa .
Inobatisa zvirimo sechinhu chinogoneka. Inobvuma sarudzo dzaungada object
.
Iwe unogona kugadzira yekudonha muenzaniso nemugadziri, semuenzaniso:
var myCollapse = document.getElementById('myCollapse')
var bsCollapse = new bootstrap.Collapse(myCollapse, {
toggle: false
})
Nzira | Tsanangudzo |
---|---|
toggle |
Inoshandura chinhu chinopeta kuti chiratidze kana kuvanzwa. Inodzokera kune ari kufona chinhu chinopeta chisati charatidzwa kana kuvanzwa (kureva kuti shown.bs.collapse kana hidden.bs.collapse chiitiko chisati chaitika). |
show |
Inoratidza chinhu chinopeta. Inodzokera kumunhu arikufona chinhu chinopeta chisati chanyatsoratidzwa (semuenzaniso, shown.bs.collapse chiitiko chisati chaitika). |
hide |
Inoviga chinhu chinopeta. Inodzokera kumunhu arikufona chinhu chinopeta chisati chavanzwa (semuenzaniso, hidden.bs.collapse chiitiko chisati chaitika). |
dispose |
Inoparadza kuputsika kwechimwe chinhu. (Inobvisa data rakachengetwa pachinhu cheDOM) |
getInstance |
Static nzira iyo inokutendera iwe kuti uwane iyo yekudonha muenzaniso yakabatana neiyo DOM chinhu, unogona kuishandisa seizvi:bootstrap.Collapse.getInstance(element) |
getOrCreateInstance |
Static nzira inodzosa chiitiko chekudonha chakabatana nechinhu cheDOM kana kugadzira chitsva kana chisina kutangwa. Unogona kuishandisa seizvi:bootstrap.Collapse.getOrCreateInstance(element) |
Zviitiko
Bootstrap's kudonha kirasi inofumura zviitiko zvishoma zvekukochekera mukudonha kushanda.
Chiitiko mhando | Tsanangudzo |
---|---|
show.bs.collapse |
Ichi chiitiko chinopisa nekukasira kana show nzira yemuenzaniso inodanwa. |
shown.bs.collapse |
Ichi chiitiko chinodzingwa kana chinhu chekudonha chaitwa kuti chionekwe kumushandisi (chinomirira kuti CSS shanduko ipedze). |
hide.bs.collapse |
Chiitiko ichi chinodzingwa pakarepo kana hide nzira yadaidzwa. |
hidden.bs.collapse |
Chiitiko ichi chinodzingwa kana chinhu chekudonha chakavanzwa kubva kumushandisi (chinomirira kuti CSS shanduko ipedze). |
var myCollapsible = document.getElementById('myCollapsible')
myCollapsible.addEventListener('hidden.bs.collapse', function () {
// do something...
})