ambruk
Ganti visibilitas konten ing proyek sampeyan kanthi sawetara kelas lan plugin JavaScript.
Klik tombol ing ngisor iki kanggo nuduhake lan ndhelikake unsur liyane liwat owah-owahan kelas:
.collapse
ndhelikake isi.collapsing
ditrapake sajrone transisi.collapse.show
nuduhake isi
Sampeyan bisa nggunakake link karo href
atribut, utawa tombol karo data-target
atribut. Ing kasus loro, data-toggle="collapse"
iku dibutuhake.
<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>
utawa <a>
bisa nuduhake lan ndhelikake sawetara unsur kanthi ngrujuk karo pamilih JQuery ing atribut href
utawa . data-target
Multiple <button>
utawa <a>
bisa nuduhake lan ndhelikake unsur yen saben referensi karo atribut href
utawadata-target
<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>
Nggunakake komponen kertu , sampeyan bisa ngluwihi prilaku ambruk standar kanggo nggawe akordion.
<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>
Dadi manawa kanggo nambah aria-expanded
menyang unsur kontrol. Atribut iki kanthi jelas nuduhake kahanan saiki saka unsur sing bisa digulung sing disambungake menyang kontrol kanggo maca layar lan teknologi pitulung sing padha. Yen unsur collapsible ditutup kanthi standar, atribut ing unsur kontrol kudu duwe nilai aria-expanded="false"
. Yen sampeyan wis nyetel unsur collapsible mbukak minangka standar nggunakake show
kelas, nyetel aria-expanded="true"
ing kontrol tinimbang. Plugin bakal kanthi otomatis ngalih atribut iki ing kontrol adhedhasar apa unsur collapsible wis dibukak utawa ditutup (liwat JavaScript, utawa amarga pangguna micu unsur kontrol liyane uga disambungake menyang unsur collapsbile padha). Yen unsur HTML unsur kontrol dudu tombol (contone, <a>
utawa <div>
), atribut kasebutrole="button"
kudu ditambahake menyang unsur.
Yen unsur kontrol sampeyan nargetake unsur sing bisa dilipat - yaiku data-target
atribut kasebut ngarah menyang id
pamilih - sampeyan kudu nambah aria-controls
atribut menyang unsur kontrol, ngemot id
unsur sing bisa dilipat. Pembaca layar modern lan teknologi bantu sing padha nggunakake atribut iki kanggo nyedhiyakake trabasan tambahan kanggo pangguna kanggo navigasi langsung menyang unsur sing bisa dilipat.
Elinga yen implementasine Bootstrap saiki ora nyakup macem-macem interaksi keyboard sing diterangake ing pola akordion WAI-ARIA Authoring Practices 1.1 - sampeyan kudu nyakup iki dhewe karo JavaScript khusus.
Plugin ambruk nggunakake sawetara kelas kanggo nangani ngangkat abot:
.collapse
ndhelikake isi.collapse.show
nuduhake isi.collapsing
ditambahake nalika transisi diwiwiti, lan dibusak nalika rampung
Kelas kasebut bisa ditemokake ing _transitions.scss
.
Mung nambah data-toggle="collapse"
lan data-target
menyang unsur kanggo otomatis nemtokake kontrol siji utawa luwih unsur collapsible. Atribut data-target
nampa pamilih CSS kanggo aplikasi ambruk kanggo. Dadi manawa kanggo nambah kelas collapse
menyang unsur collapsible. Yen sampeyan pengin mbukak standar, tambahake kelas tambahan show
.
Kanggo nambah manajemen grup kaya akordion menyang area sing bisa dilipat, tambahake atribut data data-parent="#selector"
. Deleng demo kanggo ndeleng iki ing tumindak.
Aktifake kanthi manual kanthi:
Opsi bisa dilewati liwat atribut data utawa JavaScript. Kanggo atribut data, tambahake jeneng pilihan menyang data-
, kaya ing data-parent=""
.
jeneng | Jinis | Default | Katrangan |
---|---|---|---|
wong tuwa | pamilih | obyek jQuery | unsur DOM | palsu | Yen wong tuwa diwenehake, kabeh unsur sing bisa dilipat ing sangisore wong tuwa sing ditemtokake bakal ditutup nalika item sing bisa dilipat iki ditampilake. (padha karo prilaku akordion tradisional - iki gumantung ing card kelas). Atribut kudu disetel ing target area sing bisa dilipat. |
ngalih | boolean | bener | Ngowahi unsur sing bisa dilipat ing panyuwunan |
Cara lan transisi asinkron
Kabeh cara API ora sinkron lan miwiti transisi . Dheweke bali menyang panelpon sanalika transisi diwiwiti nanging sadurunge rampung . Kajaba iku, panggilan metode ing komponen transisi bakal diabaikan .
Deleng dokumentasi JavaScript kanggo informasi luwih lengkap.
Ngaktifake konten sampeyan minangka unsur sing bisa dilipat. Nampa opsi opsional object
.
Ngalih unsur sing bisa dilipat dadi ditampilake utawa didhelikake. Bali menyang panelpon sadurunge unsur collapsible wis bener ditampilake utawa didhelikake (yaiku sadurunge shown.bs.collapse
utawa hidden.bs.collapse
acara dumadi).
Nuduhake unsur collapsible. Bali menyang panelpon sadurunge unsur collapsible wis bener wis ditampilake (ie sadurunge shown.bs.collapse
acara kedaden).
Ndhelikake unsur collapsible. Bali menyang panelpon sadurunge unsur collapsible wis bener didhelikake (yaiku sadurunge hidden.bs.collapse
acara kedaden).
Ngancurake ambruk unsur.
Kelas ambruk Bootstrap nyedhiyakake sawetara acara kanggo nyambungake fungsi ambruk.
Jinis Acara | Katrangan |
---|---|
show.bs.ambruk | Acara iki langsung murub nalika show metode conto diarani. |
ditampilake.bs.ambruk | Acara iki dipecat nalika unsur ambruk wis katon kanggo pangguna (bakal ngenteni transisi CSS rampung). |
hide.bs.ambruk | Acara iki langsung dipecat nalika hide metode kasebut diarani. |
didhelikake.bs.ambruk | Acara iki dipecat nalika unsur ambruk wis didhelikake saka pangguna (bakal ngenteni transisi CSS rampung). |