Kugwa
Sinthani kuwonekera kwa zomwe zili mu projekiti yanu ndi makalasi angapo ndi mapulagini athu a JavaScript.
Momwe zimagwirira ntchito
Pulogalamu yowonjezera ya JavaScript imagwiritsidwa ntchito kusonyeza ndi kubisa zomwe zili. Mabatani kapena anangula amagwiritsidwa ntchito ngati zoyambitsa zomwe zimajambulidwa kuzinthu zinazake zomwe mumasintha. Kugwetsa chinthu kumapangitsa kuti chinthucho height
chichoke pamtengo wake wapano mpaka 0
. Poganizira momwe CSS imagwirira ntchito makanema ojambula, simungagwiritse ntchito padding
pa .collapse
chinthu. M'malo mwake, gwiritsani ntchito kalasi ngati chinthu chodzikulunga chodziyimira payokha.
prefers-reduced-motion
funso la media. Onani gawo
lochepetsedwa la zolemba zathu zofikira .
Chitsanzo
Dinani mabatani omwe ali pansipa kuti muwonetse ndikubisa chinthu china kudzera mukusintha kwamakalasi:
.collapse
amabisa zomwe zili.collapsing
imagwiritsidwa ntchito panthawi ya kusintha.collapse.show
zikuwonetsa zomwe zili
Nthawi zambiri, timalimbikitsa kugwiritsa ntchito batani lokhala ndi mawonekedwe data-target
. Ngakhale osavomerezedwa kuchokera kumalingaliro a semantic, mutha kugwiritsanso ntchito ulalo wokhala ndi href
malingaliro (ndi a role="button"
). Muzochitika zonsezi, data-toggle="collapse"
ndikofunikira.
<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">
Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
</div>
</div>
Chopingasa
Pulagi ya kugwa imathandiziranso kugwa kopingasa. Onjezani .width
kalasi yosinthira kuti musinthe width
m'malo mwake height
ndikuyika width
pa chinthu chomwe chilipo mwana. Khalani omasuka kulemba makonda anu a Sass, gwiritsani ntchito masitayelo apaintaneti, kapena gwiritsani ntchito zida zathu zakufalikira .
min-height
lopewa kupentanso mopitilira muyeso muzolemba zathu, izi sizofunikira.
Zomwe zili pamwana zokha width
ndizofunikira.
<p>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseWidthExample" aria-expanded="false" aria-controls="collapseWidthExample">
Toggle width collapse
</button>
</p>
<div style="min-height: 120px;">
<div class="collapse width" id="collapseWidthExample">
<div class="card card-body" style="width: 320px;">
This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
</div>
</div>
</div>
Zolinga zingapo
A <button>
kapena <a>
atha kuwonetsa ndikubisa zinthu zingapo powalozera ndi chosankha cha JQuery mu zake href
kapena mawonekedwe ake data-target
. Angapo <button>
kapena atha kuwonetsa <a>
ndikubisa chinthu ngati aliyense amachitchula ndi mawonekedwe href
akedata-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">
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>
Chitsanzo cha accordion
Pogwiritsa ntchito chigawo cha khadi , mutha kukulitsa khalidwe la kugwa kosasintha kuti mupange accordion. Kuti mukwaniritse bwino kalembedwe ka accordion, onetsetsani kuti mukugwiritsa ntchito .accordion
ngati wrapper.
.show
kalasi.
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</button>
</h2>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
Some placeholder content for the first accordion panel. This panel is shown by default, thanks to the <code>.show</code> class.
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</button>
</h2>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
Some placeholder content for the second accordion panel. This panel is hidden by default.
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Collapsible Group Item #3
</button>
</h2>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
<div class="card-body">
And lastly, the placeholder content for the third and final accordion panel. This panel is hidden by default.
</div>
</div>
</div>
</div>
Kufikika
Onetsetsani kuti muwonjezere aria-expanded
ku chinthu chowongolera. Chizindikirochi chikuwonetsa bwino momwe zinthu zomwe zimasokonekera zomwe zimalumikizidwa ndi zowongolera zowerengera zowonera ndi matekinoloje othandizira ofanana. Ngati chinthu chosokonekera chatsekedwa mwachisawawa, chikhumbo cha chinthu chowongolera chiyenera kukhala ndi mtengo wa aria-expanded="false"
. Ngati mwakhazikitsa chinthu chogonja kuti chitsegulidwe mwachisawawa pogwiritsa ntchito show
kalasi, ikani aria-expanded="true"
chowongolera m'malo mwake. Pulagiyi imangosintha izi pakuwongolera kutengera ngati chinthu chomwe chitha kugubuduka chatsegulidwa kapena kutsekedwa (kudzera pa JavaScript, kapena chifukwa wogwiritsa ntchitoyo adayambitsa chinthu china chowongolera chomwe chimamangiriridwanso ku chinthu chomwe chimatha). Ngati chinthu chowongolera cha HTML si batani (mwachitsanzo, <a>
kapena <div>
), mawonekedwerole="button"
ziyenera kuwonjezeredwa ku element.
Ngati chinthu chomwe mumayang'anira chikuyang'ana chinthu chimodzi chomwe chimatha kugwa - mwachitsanzo, mawonekedwewo data-target
akulozera kwa id
chosankha - muyenera kuwonjezera chizindikiritso aria-controls
ku chinthu chowongolera, chomwe chili ndi id
chinthu chomwe chimatha kugwa. Owerenga zenera amakono ndi matekinoloje othandizira ofanana amagwiritsa ntchito izi kuti apatse ogwiritsa ntchito njira zazifupi kuti ayende molunjika ku chinthu chomwe chimasokonekera chokha.
Dziwani kuti kukhazikitsidwa kwa Bootstrap pakadali pano sikukhudzana ndi machitidwe osiyanasiyana a kiyibodi omwe akufotokozedwa mu ARIA Authoring Practices Guide accordion pattern - muyenera kuziphatikiza nokha ndi JavaScript.
Kugwiritsa ntchito
Pulagi ya kugwa imagwiritsa ntchito makalasi angapo kuti athe kunyamula zolemetsa:
.collapse
amabisa zomwe zili.collapse.show
zikuwonetsa zomwe zili.collapsing
imawonjezeredwa pamene kusintha kukuyamba, ndikuchotsedwa ikatha
Maphunzirowa amapezeka mu _transitions.scss
.
Kudzera muzochita za data
Ingowonjezerani data-toggle="collapse"
ndi a data-target
ku chinthucho kuti muzitha kuwongolera chinthu chimodzi kapena zingapo zomwe zimatha kutha. Malingaliro data-target
amavomereza chosankha cha CSS kuti agwiritse ntchito kugwa. Onetsetsani kuti mwawonjezera kalasi collapse
ku chinthu chomwe chimatha. Ngati mukufuna kuti isatseguke, onjezani kalasi yowonjezera show
.
Kuti muwonjeze kasamalidwe ka gulu ngati accordion kumalo otha kugwa, onjezani mawonekedwe a data data-parent="#selector"
. Onani pachiwonetsero kuti muwone izi zikugwira ntchito.
Kudzera pa JavaScript
Yambitsani pamanja ndi:
$('.collapse').collapse()
Zosankha
Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-
, monga mu data-parent=""
.
Dzina | Mtundu | Zosasintha | Kufotokozera |
---|---|---|---|
kholo | kusankha | jQuery chinthu | Chithunzi cha DOM | zabodza | Ngati kholo liperekedwa, ndiye kuti zinthu zonse zomwe zimasokonekera pansi pa khololo zidzatsekedwa chinthu chosokonekerachi chiwonetsedwa. (zofanana ndi chikhalidwe cha accordion - izi zimadalira card kalasi). Chikhalidwecho chiyenera kukhazikitsidwa pa malo omwe angagwe. |
kusintha | boolean | zoona | Imasintha chinthu chomwe chimasokonekera pakuyitanitsa |
Njira
Asynchronous njira ndi kusintha
Njira zonse za API ndizosasinthika ndipo zimayamba kusintha . Amabwerera kwa woyimbayo atangoyamba kusintha koma asanathe . Kuonjezera apo, kuyitana kwa njira pa gawo losintha kudzanyalanyazidwa .
.collapse(options)
Imatsegula zomwe zili patsamba lanu ngati chinthu chosokonekera. Imavomereza zomwe mungachite object
.
$('#myCollapsible').collapse({
toggle: false
})
.collapse('toggle')
Imasintha zinthu zomwe zimagundika kuti ziwonetsedwe kapena zobisika. Imabwereranso kwa woyimbayo chinthu chomwe chingathe kutha sichinasonyezedwe kapena kubisika (ie chisanachitike shown.bs.collapse
kapena hidden.bs.collapse
chochitikacho).
.collapse('show')
Imawonetsa chinthu chomwe chimatha kutha. Imabwereranso kwa woyimbayo chinthu chomwe chingathe kugwetsedwa chisanasonyezedwe (mwachitsanzo, shown.bs.collapse
chochitikacho chisanachitike).
.collapse('hide')
Imabisa chinthu chomwe chimatha kutha. Imabwereranso kwa woyimbirayo chinthu chosokonekera chisanabisike (mwachitsanzo, hidden.bs.collapse
chochitikacho chisanachitike).
.collapse('dispose')
Imawononga kugwa kwa chinthu.
Zochitika
Gulu la kugwa la Bootstrap limawulula zochitika zingapo kuti zigwirizane ndi kugwa.
Mtundu wa Chochitika | Kufotokozera |
---|---|
onetsani.bs.kugwa | Chochitika ichi chimayaka nthawi yomweyo show njira yachitsanzo itayitanidwa. |
zowonetsedwa.bs.kugwa | Chochitikachi chimachotsedwa pomwe chinthu chakugwa chawonetsedwa kwa wogwiritsa ntchito (chidikirira kuti kusintha kwa CSS kumalize). |
kubisa.bs.gwa | Chochitikachi chimathamangitsidwa nthawi yomweyo hide njirayo itayitanidwa. |
zobisika.bs.kugwa | Chochitikachi chimachotsedwa pomwe chinthu chakugwa chabisidwa kwa wogwiritsa ntchito (chidikirira kuti kusintha kwa CSS kumalize). |
$('#myCollapsible').on('hidden.bs.collapse', function () {
// do something...
})