Source

Ukuwa

Guqula ukubonakala komxholo kuyo yonke iprojekthi yakho ngeeklasi ezimbalwa kunye neeplagi zethu zeJavaScript.

Umzekelo

Cofa amaqhosha angezantsi ukuze ubonise kwaye ufihle enye into ngotshintsho lweklasi:

  • .collapseifihla umxholo
  • .collapsingisetyenziswa ngexesha lotshintsho
  • .collapse.showibonisa umxholo

Ungasebenzisa ikhonkco kunye hrefnophawu, okanye iqhosha elinophawu data-targetloyelelwano. Kuzo zombini ezi meko, data-toggle="collapse"kuyafuneka.

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

Iithagethi ezininzi

I-A <button>okanye <a>ingabonisa kwaye ifihle izinto ezininzi ngokuzibhekisa kunye nomkhethi we-JQuery kuyo hrefokanye data-targetuphawu. Zininzi <button>okanye <a>zinokubonisa kwaye zifihle into ukuba nganye ibhekisa kuyo hrefkunye data-targetnophawu

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

Umzekelo weAccordion

Usebenzisa icandelo lekhadi , unokwandisa ukuziphatha kokudilika okungagqibekanga ukwenza iakhodiyoni.

Anim pariatur cliche reprehenderit, enim eiusmod ubomi obuphezulu accamus terry richardson ad squid. 3 ingcuka inyanga officia aute, non cupidatat skateboard dolor brunch. Ilori yokutya iquinoa nesciunt laborum eiusmod. Brunch 3 ingcuka inyanga tempor, sunt aliqua ubeke intaka kuyo iskwidi enye-imvelaphi ikofu nulla imaginenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. I-Leggings occaecat yenza ibhiya yasefama-kuya-kwitafile, idenim ekrwada i-aesthetic synth nesciunt mhlawumbi awuzange uve ngabo accusamus labour ezinzileyo yeVHS.
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.
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 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>

Ukufikeleleka

Qinisekisa ukuba wongeza aria-expandedkwinto yolawulo. Olu phawu lubonisa ngokucacileyo imeko yangoku yento eqengqelekayo ebotshelelwe kulawulo kwizifundi zesikrini kunye nobuchwephesha obuncedisayo obufanayo. Ukuba isiqalelo esiqengqelekayo sivalwe ngokungagqibekanga, uphawu loyelelwano lwento yolawulo kufuneka lube nexabiso aria-expanded="false". Ukuba usete into eqengqelekayo ukuba ivuleke ngokungagqibekanga usebenzisa showiklasi, misela aria-expanded="true"kulawulo endaweni yoko. Iplagi iya kuzitshintsha ngokuzenzekela olu phawu kulawulo olusekwe ekubeni ngaba into eqengqelekayo ivuliwe okanye ayivalwanga (ngeJavaScript, okanye ngenxa yokuba umsebenzisi eqalise enye into yolawulo ekwadityaniswe kwaloo nto inye i collapsbile element). Ukuba isiqalelo solawulo se HTML asiloqhosha (umzekelo, i <a>okanye <div>), uphawurole="button"kufuneka yongezwe kwisiqalelo.

Ukuba isiqalelo sakho solawulo sijolise kwinto enye eqengqelekayo - oko kukuthi data-targetuphawu lwalatha idkumkhethi - kufuneka wongeze aria-controlsuphawu lwento yolawulo, equlathe idinto eqengqelekayo. Izifundi zesikrini zanamhlanje kunye neetekhnoloji ezincedisayo ezifanayo zisebenzisa olu phawu ukunika abasebenzisi iindlela ezimfutshane ukuya ngqo kwinto egobekayo ngokwayo.

Qaphela ukuba uphumezo lwangoku lweBootstrap aluquki udibaniso lwebhodi yezitshixo ezahlukeneyo ezichazwe kwi- WAI-ARIA yokuBhalisa iipatheni 1.1 ipateni yeaccordion - kuya kufuneka uzibandakanye ngokwakho kunye neJavaScript yesiko.

Ukusetyenziswa

Iplagin yokuwa isebenzisa iiklasi ezimbalwa ukuphatha ukuphakamisa okunzima:

  • .collapseifihla umxholo
  • .collapse.showibonisa umxholo
  • .collapsingyongezwa xa inguqu iqala, kwaye isuswe xa igqibile

Ezi klasi zinokufumaneka kwi _transitions.scss.

Ngeempawu zedatha

Yongeza nje data-toggle="collapse"kunye no data-target-a kwisiqalelo ukwabela ngokuzenzekelayo ulawulo lwento enye okanye ezininzi eziqengqelekayo. Uphawu data-targetloyelelwano lwamkela umkhethi we-CSS ukuze kufakwe ukutshitshiswa. Qinisekisa ukuba wongeza iklasi collapsekwinto eqengqelekayo. Ukuba ungathanda ukuba ivuleke ngokungagqibekanga, yongeza udidi olongezelelweyo show.

Ukongeza ulawulo lweqela olufana ne-accordion kwindawo egotywayo, yongeza uphawu loyelelwano lwedatha data-parent="#selector". Jonga kwidemo ukuze ubone oku kusebenza.

NgeJavaScript

Vula ngesandla nge:

$('.collapse').collapse()

Iinketho

Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-, njengakwi data-parent="".

Igama Uhlobo Ukuhlala kukho Inkcazo
umzali umkhethi | jQuery into | Into ye-DOM bubuxoki Ukuba umzali unikiwe, ke zonke izinto eziqengqelekayo phantsi komzali ochaziweyo ziya kuvalwa xa le nto iqengqelekayo iboniswa. (efana nokuziphatha kwe-accordion yendabuko - oku kuxhomekeke cardkwiklasi). Uphawu kufuneka lubekwe kwindawo ekujoliswe kuyo egotywayo.
guqula boolean yinyani Qwalasela into eqengqelekayo kubizo

Iindlela

Iindlela ze-Asynchronous kunye notshintsho

Zonke iindlela ze-API zi -asynchronous kwaye ziqala utshintsho . Babuyela kumnxeba ngokukhawuleza nje ukuba utshintsho luqalisiwe kodwa ngaphambi kokuba luphele . Ukongeza, ukufowunelwa kwendlela kwicandelo lenguquko kuya kuhoywa .

Jonga uxwebhu lwethu lweJavaScript ngolwazi olungakumbi.

.collapse(options)

Yenza umxholo wakho ube yinto eqengqelekayo. Yamkela iinketho ozikhethelayo object.

$('#myCollapsible').collapse({
  toggle: false
})

.collapse('toggle')

Iguqulela into eqengqelekayo ukuze iboniswe okanye ifihliwe. Ibuyisela kumnxeba phambi kokuba into eqengqelekayo iboniswe okanye ifihliwe (okt phambi kokuba isiganeko shown.bs.collapseokanye hidden.bs.collapseisiganeko senzeke).

.collapse('show')

Ibonisa into eqengqelekayo. Ibuyisela kumnxeba phambi kokuba into eqengqelekayo iboniswe (okt phambi kokuba shown.bs.collapseisiganeko senzeke).

.collapse('hide')

Ifihla into eqengqelekayo. Ibuyisela kumnxebi phambi kokuba into eqengqelekayo ifihlwe (okt phambi kokuba hidden.bs.collapseisiganeko senzeke).

.collapse('dispose')

Itshabalalisa ukuwa kwento.

Iziganeko

Iklasi yokuwa yeBootstrap iveza iminyhadala embalwa yokuhuka ekusebenzeni kokuwa.

Uhlobo loMnyhadala Inkcazo
bonisa.bs.collapse Esi siganeko sivutha ngokukhawuleza xa showkubizwa indlela yomzekelo.
ibonisiwe.bs.collapse Esi siganeko sigxothwa xa into yokudilika yenziwe yabonakala kumsebenzisi (iya kulinda iinguqu zeCSS ukuba zigqibe).
fihla.bs.coqa Esi siganeko sigxothwa ngokukhawuleza xa hideindlela sele ibizwa.
efihliweyo.bs.ukudilika Esi siganeko sigxothwa xa into yokudilika ifihliwe kumsebenzisi (iya kulinda iinguqu zeCSS ukuba zigqibe).
$('#myCollapsible').on('hidden.bs.collapse', function () {
  // do something…
})