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 heightchichoke pamtengo wake wapano mpaka 0. Poganizira momwe CSS imagwirira ntchito makanema ojambula, simungagwiritse ntchito paddingpa .collapsechinthu. M'malo mwake, gwiritsani ntchito kalasi ngati chinthu chodzikulunga chodziyimira payokha.

Zotsatira zamakanema za gawoli zimatengera prefers-reduced-motionfunso la media. Onani gawo lochepetsedwa la zolemba zathu zofikira .

Chitsanzo

Dinani mabatani omwe ali pansipa kuti muwonetse ndikubisa chinthu china kudzera mukusintha kwamakalasi:

  • .collapseamabisa zomwe zili
  • .collapsingimagwiritsidwa ntchito panthawi ya kusintha
  • .collapse.showzikuwonetsa 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 hrefmalingaliro (ndi a role="button"). Muzochitika zonsezi, data-toggle="collapse"ndikofunikira.

Some placeholder content for the collapse component. This panel is hidden by default but revealed when the user activates the relevant trigger.
<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 .widthkalasi yosinthira kuti musinthe widthm'malo mwake heightndikuyika widthpa chinthu chomwe chilipo mwana. Khalani omasuka kulemba makonda anu a Sass, gwiritsani ntchito masitayelo apaintaneti, kapena gwiritsani ntchito zida zathu zakufalikira .

Chonde dziwani kuti ngakhale chitsanzo chili m'munsichi chili ndi dongosolo min-heightlopewa kupentanso mopitilira muyeso muzolemba zathu, izi sizofunikira. Zomwe zili pamwana zokha widthndizofunikira.

This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
<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 hrefkapena mawonekedwe ake data-target. Angapo <button>kapena atha kuwonetsa <a>ndikubisa chinthu ngati aliyense amachitchula ndi mawonekedwe hrefakedata-target

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.
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.
<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 .accordionngati wrapper.

Zina zosungira malo za gulu loyamba la accordion. Gululi likuwonetsedwa mwachisawawa, chifukwa cha .showkalasi.

Some placeholder content for the second accordion panel. This panel is hidden by default.

And lastly, the placeholder content for the third and final accordion panel. This panel is hidden by default.
<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-expandedku 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 showkalasi, 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-targetakulozera kwa idchosankha - muyenera kuwonjezera chizindikiritso aria-controlsku chinthu chowongolera, chomwe chili ndi idchinthu 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:

  • .collapseamabisa zomwe zili
  • .collapse.showzikuwonetsa zomwe zili
  • .collapsingimawonjezeredwa pamene kusintha kukuyamba, ndikuchotsedwa ikatha

Maphunzirowa amapezeka mu _transitions.scss.

Kudzera muzochita za data

Ingowonjezerani data-toggle="collapse"ndi a data-targetku chinthucho kuti muzitha kuwongolera chinthu chimodzi kapena zingapo zomwe zimatha kutha. Malingaliro data-targetamavomereza chosankha cha CSS kuti agwiritse ntchito kugwa. Onetsetsani kuti mwawonjezera kalasi collapseku 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 cardkalasi). 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 .

Onani zolemba zathu za JavaScript kuti mudziwe zambiri .

.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.collapsekapena hidden.bs.collapsechochitikacho).

.collapse('show')

Imawonetsa chinthu chomwe chimatha kutha. Imabwereranso kwa woyimbayo chinthu chomwe chingathe kugwetsedwa chisanasonyezedwe (mwachitsanzo, shown.bs.collapsechochitikacho chisanachitike).

.collapse('hide')

Imabisa chinthu chomwe chimatha kutha. Imabwereranso kwa woyimbirayo chinthu chosokonekera chisanabisike (mwachitsanzo, hidden.bs.collapsechochitikacho 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 shownjira 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 hidenjirayo 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...
})