Source

Kaw

Toggle qhov pom ntawm cov ntsiab lus thoob plaws koj qhov project nrog ob peb chav kawm thiab peb cov JavaScript plugins.

Nws ua haujlwm li cas

Lub cev qhuav dej JavaScript plugin yog siv los qhia thiab zais cov ntsiab lus. Cov nyees khawm lossis cov thauj tog rau nkoj yog siv los ua cov cim uas tau teeb tsa rau cov ntsiab lus tshwj xeeb uas koj hloov pauv. Collapsing ib lub caij yuav animate heightlos ntawm nws cov nqi tam sim no rau 0. Muab CSS ua haujlwm li cas rau cov animations, koj siv tsis tau paddingntawm ib lub .collapsecaij. Hloov chaw, siv cov chav kawm ua ib qho kev nthuav dav ntawm cov ntaub qhwv.

Cov nyhuv animation ntawm cov khoom siv no yog nyob ntawm cov prefers-reduced-motionlus nug xov xwm. Saib qhov txo qis ntawm peb cov ntaub ntawv nkag mus tau .

Piv txwv

Nyem rau cov nyees khawm hauv qab no los qhia thiab zais lwm lub ntsiab lus ntawm kev hloov hauv chav kawm:

  • .collapsezais cov ntsiab lus
  • .collapsingyog siv thaum lub sij hawm hloov
  • .collapse.showqhia cov ntsiab lus

Koj tuaj yeem siv qhov txuas nrog tus hrefcwj pwm, lossis khawm nrog tus data-targetcwj pwm. Hauv ob qho xwm txheej, qhov data-toggle="collapse"yuav tsum tau ua.

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>

Ntau lub hom phiaj

Ib <button>lossis <a>tuaj yeem qhia thiab zais ntau lub ntsiab lus los ntawm kev xa lawv nrog JQuery selector hauv nws hreflossis data-targettus cwj pwm. Ntau <button>lossis <a>tuaj yeem qhia thiab zais ib lub ntsiab lus yog tias lawv txhua tus siv nrog lawv hreflossis data-targettus cwj pwm

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>

Piv txwv li accordion

Siv daim npav tivthaiv, koj tuaj yeem txuas ntxiv qhov kev coj cwj pwm tsis zoo los tsim cov accordion. Yuav kom ua tiav lub accordion style, nco ntsoov siv .accordionraws li ib tug wrapper.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 hma hli official aute, non cupidatat skateboard dolor brunch. Khoom noj khoom haus tsheb quinoa nesciunt lab eiusmod. Brunch 3 hma hli tempor, sunt aliqua muab ib tug noog rau nws squid ib leeg-hauv paus kas fes nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer laboure wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur neeg tua tsiaj vice lomo. Leggings occaecat khoom siv tes ua npias ua liaj ua teb-rau- rooj, nyoos denim aesthetic synth nesciunt tej zaum koj tsis tau hnov ​​​​txog lawv accusamus ua haujlwm ruaj khov 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.

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 class="accordion" id="accordionExample">
  <div class="card">
    <div class="card-header" id="headingOne">
      <h2 class="mb-0">
        <button class="btn btn-link" 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">
        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">
      <h2 class="mb-0">
        <button class="btn btn-link 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">
        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">
      <h2 class="mb-0">
        <button class="btn btn-link 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">
        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>

Kev siv tau

Nco ntsoov ntxiv aria-expandedrau lub caij tswj. Tus cwj pwm no qhia meej meej txog lub xeev tam sim no ntawm lub caij sib tsoo khi rau kev tswj kom tshuaj xyuas cov neeg nyeem thiab cov thev naus laus zis zoo sib xws. Yog tias lub caij collapsible raug kaw los ntawm lub neej ntawd, tus cwj pwm ntawm cov khoom tswj yuav tsum muaj tus nqi ntawm aria-expanded="false". Yog tias koj tau teeb tsa lub caij collapsible kom qhib los ntawm lub neej ntawd siv cov showchav kawm, teem caij aria-expanded="true"rau kev tswj hwm. Lub plugin yuav cia li toggle tus cwj pwm no ntawm kev tswj xyuas raws li seb puas tau qhib lossis kaw (ntawm JavaScript, lossis vim tias tus neeg siv ua rau lwm qhov kev tswj hwm kuj tau khi rau tib lub caij sib tsoo). Yog hais tias tus tswj hwm lub ntsiab HTML tsis yog khawm (piv txwv li, ib qho <a>lossis <div>), tus cwj pwmrole="button"yuav tsum tau ntxiv rau lub caij.

Yog tias koj lub ntsiab tswj yog tsom rau ib qho kev sib tsoo - piv txwv li tus data-targetcwj pwm yog taw tes rau tus idxaiv - koj yuav tsum ntxiv tus aria-controlscwj pwm rau cov khoom tswj, uas muaj cov idkhoom sib tsoo. Cov ntawv nyeem niaj hnub no thiab cov thev naus laus zis zoo sib xws ua rau siv cov cwj pwm no los muab cov neeg siv nrog cov shortcuts ntxiv rau kev taw qhia ncaj qha rau lub caij sib tsoo nws tus kheej.

Nco ntsoov tias Bootstrap qhov kev siv tam sim no tsis suav nrog ntau yam kev sib cuam tshuam ntawm cov keyboard tau piav qhia hauv WAI-ARIA Authoring Practices 1.1 accordion qauv - koj yuav tsum suav nrog koj tus kheej nrog kev cai JavaScript.

Kev siv

Lub cev qhuav dej siv ob peb chav kawm los daws qhov hnyav nqa:

  • .collapsezais cov ntsiab lus
  • .collapse.showqhia cov ntsiab lus
  • .collapsingntxiv thaum qhov kev hloov pauv pib, thiab tshem tawm thaum nws tiav

Cov chav kawm no tuaj yeem pom hauv _transitions.scss.

Los ntawm cov ntaub ntawv attributes

Tsuas yog ntxiv data-toggle="collapse"thiab ib qho data-targetrau lub caij kom tau txais kev tswj hwm ntawm ib lossis ntau lub ntsiab lus collapsible. Tus data-targetcwj pwm lees txais CSS xaiv los siv lub cev qhuav dej rau. Nco ntsoov ntxiv cov chav kawm collapserau lub caij collapsible. Yog tias koj xav kom nws qhib lub neej ntawd, ntxiv cov chav kawm ntxiv show.

Txhawm rau ntxiv accordion-zoo li pab pawg tswj hwm rau thaj tsam collapsible, ntxiv cov ntaub ntawv tus cwj pwm data-parent="#selector". Xa mus rau qhov demo kom pom qhov no hauv kev nqis tes ua.

Ntawm JavaScript

Qhib manually nrog:

$('.collapse').collapse()

Kev xaiv

Cov kev xaiv tuaj yeem dhau los ntawm cov ntaub ntawv tus cwj pwm lossis JavaScript. Rau cov ntaub ntawv tus cwj pwm, ntxiv rau qhov kev xaiv npe rau data-, xws li hauv data-parent="".

Lub npe Hom Default Kev piav qhia
niam txiv xaiv | jQuery khoom | DOM Element cuav Yog tias niam txiv muab, ces tag nrho cov ntsiab lus collapsible nyob rau hauv cov niam txiv uas tau teev tseg yuav raug kaw thaum cov khoom sib tsoo no tshwm sim. (zoo ib yam li kev coj cwj pwm accordion - qhov no yog nyob ntawm cardchav kawm). Tus cwj pwm yuav tsum tau teem rau ntawm lub hom phiaj collapsible.
toggle boolean muaj tseeb Toggles lub caij collapsible ntawm invocation

Cov txheej txheem

Asynchronous txoj kev thiab kev hloov

Txhua txoj kev API yog asynchronous thiab pib hloov pauv . Lawv rov qab mus rau tus neeg hu xov tooj sai li sai tau thaum qhov kev hloov pauv pib tab sis ua ntej nws xaus . Tsis tas li ntawd, ib txoj kev hu rau ib qho kev hloov pauv yuav raug tsis quav ntsej .

Saib peb cov ntaub ntawv JavaScript kom paub ntau ntxiv .

.collapse(options)

Activates koj cov ntsiab lus raws li ib tug collapsible caij. Txais ib qho kev xaiv xaiv object.

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

.collapse('toggle')

Toggles lub caij collapsible kom pom los yog zais. Rov qab mus rau tus neeg hu ua ntej lub caij collapsible tau tshwm sim los yog zais (piv txwv li ua ntej qhov shown.bs.collapsekev hidden.bs.collapsetshwm sim tshwm sim).

.collapse('show')

Qhia ib lub caij collapsible. Rov qab mus rau tus neeg hu ua ntej lub caij collapsible tau tshwm sim tiag tiag (piv txwv li ua ntej qhov shown.bs.collapsexwm txheej tshwm sim).

.collapse('hide')

Hide ib lub caij collapsible. Rov qab mus rau tus neeg hu ua ntej lub caij collapsible tau muab zais tiag tiag (piv txwv li ua ntej qhov hidden.bs.collapsexwm txheej tshwm sim).

.collapse('dispose')

Destroys ib lub caij poob.

Cov xwm txheej

Bootstrap's collapse class exposes ob peb txheej xwm rau hooking mus rau hauv vau functionality.

Hom xwm txheej Kev piav qhia
show.bs.collapse Qhov xwm txheej no tua hluav taws tam sim ntawd thaum showhu ua piv txwv.
pom.bs.collapse Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub caij sib tsoo tau ua kom pom rau tus neeg siv (yuav tos rau CSS kev hloov pauv kom tiav).
hide.bs.collapse Qhov kev tshwm sim no raug rho tawm haujlwm tam sim ntawd thaum hidehu ua txoj kev.
zais.bs.collapse Qhov xwm txheej no raug rho tawm haujlwm thaum lub caij sib tsoo tau muab zais los ntawm tus neeg siv (yuav tos rau CSS kev hloov pauv kom tiav).
$('#myCollapsible').on('hidden.bs.collapse', function () {
  // do something…
})