Aktive vizibilite kontni atravè pwojè ou a ak kèk klas ak grefon JavaScript nou yo.

Ki jan li fonksyone

Yo itilize plugin JavaScript efondre pou montre ak kache kontni. Bouton oswa lank yo itilize kòm deklannche ki trase nan eleman espesifik ou aktive. Efondreman yon eleman pral anime a heightsoti nan valè aktyèl li a 0. Bay fason CSS okipe animasyon, ou pa ka itilize paddingsou yon .collapseeleman. Olye de sa, sèvi ak klas la kòm yon eleman anbalaj endepandan.

Efè animasyon eleman sa a depann de prefers-reduced-motionrechèch medya yo. Gade seksyon mouvman redui nan dokiman aksè nou an .

Egzanp

Klike sou bouton ki anba yo pou montre ak kache yon lòt eleman atravè chanjman klas yo:

  • .collapsekache kontni
  • .collapsingyo aplike pandan tranzisyon yo
  • .collapse.showmontre kontni

Anjeneral, nou rekòmande pou itilize yon bouton ki gen data-targetatribi a. Pandan ke yo pa rekòmande nan yon pwen de vi semantik, ou ka tou itilize yon lyen ak hrefatribi a (ak yon role="button"). Nan de ka yo, data-toggle="collapse"li nesesè.

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>

Orizontal

Plugin efondreman an sipòte tou efondreman orizontal. Ajoute .widthklas modifikatè a nan tranzisyon an widtholye pou yo heightepi mete yon widthsou eleman imedya pitit la. Ezite ekri pwòp Sass koutim ou a, sèvi ak estil enline, oswa itilize sèvis piblik lajè nou yo .

Tanpri sonje ke byenke egzanp ki anba a gen yon min-heightseri pou evite twòp repenn nan dokiman nou yo, sa a pa klèman obligatwa. Se sèlman widthsou eleman timoun nan obligatwa.

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>

Objektif miltip

Yon <button>oswa <a>ka montre ak kache plizyè eleman lè w refere yo ak yon seleksyon JQuery nan atribi hrefli yo. data-targetPlizyè <button>oswa <a>ka montre ak kache yon eleman si yo chak fè referans li ak atribi yo hrefoswa yodata-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>

Egzanp akòdeyon

Sèvi ak eleman kat la, ou ka pwolonje konpòtman an efondreman default yo kreye yon akòdeyon. Pou byen reyalize style akòdeyon an, asire w ke ou itilize .accordionkòm yon anbalaj.

Gen kèk kontni anplasman pou premye panèl akòdeyon an. Panèl sa a montre pa defo, gras ak .showklas la.

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>

Aksesiblite

Asire ou ke ou ajoute aria-expandednan eleman kontwòl la. Atribi sa a eksplisitman transmèt eta aktyèl la nan eleman ki rabat la mare nan kontwòl la nan lektè ekran ak teknoloji asistans menm jan an. Si eleman plimyab la fèmen pa default, atribi sou eleman kontwòl la ta dwe gen yon valè aria-expanded="false". Si ou te mete eleman ki rabat la louvri pa default lè l sèvi avèk showklas la, mete aria-expanded="true"sou kontwòl la pito. Plugin a pral otomatikman baskile atribi sa a sou kontwòl la selon si wi ou non eleman ki plizyè a te louvri oswa fèmen (via JavaScript, oswa paske itilizatè a deklanche yon lòt eleman kontwòl tou mare nan menm eleman an pliye). Si eleman HTML eleman kontwòl la se pa yon bouton (egzanp, yon <a>oswa <div>), atribi arole="button"ta dwe ajoute nan eleman an.

Si eleman kontwòl ou a ap vize yon sèl eleman ki plizye - sa vle di data-targetatribi a ap lonje dwèt sou yon idseleksyon - ou ta dwe ajoute aria-controlsatribi a nan eleman kontwòl la, ki gen ladan ideleman ki pliye a. Lektè ekran modèn yo ak teknoloji asistans ki sanble yo sèvi ak atribi sa a pou bay itilizatè yo rakoursi adisyonèl pou navige dirèkteman nan eleman ki rabat nan tèt li.

Remake byen ke aplikasyon Bootstrap aktyèl la pa kouvri divès kalite entèraksyon klavye ki dekri nan modèl akòdeyon Gid Pratik Otè ARIA a - w ap bezwen mete sa yo tèt ou ak JavaScript koutim.

Itilizasyon

Plugin efondreman an itilize kèk klas pou okipe leve lou:

  • .collapsekache kontni an
  • .collapse.showmontre kontni an
  • .collapsingyo ajoute lè tranzisyon an kòmanse, epi li retire lè li fini

Ou ka jwenn klas sa yo nan _transitions.scss.

Via atribi done yo

Jis ajoute data-toggle="collapse"ak yon data-targetnan eleman nan otomatikman bay kontwòl youn oswa plis eleman plim. Atribi a data-targetaksepte yon seleksyon CSS pou aplike efondreman an. Asire ou ke ou ajoute klas collapsela nan eleman ki rabat. Si ou ta renmen li louvri defo, ajoute klas adisyonèl la show.

Pou ajoute jesyon gwoup ki sanble ak akòdeyon nan yon zòn ki rabat, ajoute atribi done yo data-parent="#selector". Al gade nan Demo a pou wè sa a an aksyon.

Via JavaScript

Pèmèt manyèlman ak:

$('.collapse').collapse()

Opsyon

Opsyon yo ka pase atravè atribi done oswa JavaScript. Pou atribi done, ajoute non opsyon a nan data-, tankou nan data-parent="".

Non Kalite Default Deskripsyon
paran seleksyon | jQuery objè | Eleman DOM fo Si yo bay paran yo, lè sa a tout eleman plimyab ki anba paran espesifye yo pral fèmen lè yo montre atik plimyab sa a. (menm jan ak konpòtman akòdeyon tradisyonèl - sa a depann sou cardklas la). Gen atribi a dwe mete sou zòn nan sib eklatman.
baskile booleyen vre Aktivite eleman ki rabat sou envokasyon

Metòd

Metòd asynchrone ak tranzisyon

Tout metòd API yo asenkron epi yo kòmanse yon tranzisyon . Yo retounen kote moun k ap rele a le pli vit ke tranzisyon an kòmanse men anvan li fini . Anplis de sa, yo pral inyore yon apèl metòd sou yon eleman tranzisyon .

Gade dokiman JavaScript nou an pou plis enfòmasyon .

.collapse(options)

Aktive kontni ou kòm yon eleman plim. Aksepte yon opsyon opsyonèl object.

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

.collapse('toggle')

Baskile yon eleman ki rabat pou montre oswa kache. Retounen bay moun k ap rele a anvan yo te montre oswa kache eleman ki rabat (sa vle di anvan evènman shown.bs.collapsean hidden.bs.collapserive).

.collapse('show')

Montre yon eleman rabat. Retounen bay moun k ap rele a anvan yo te montre eleman ki rabat la (sa vle di anvan shown.bs.collapseevènman an rive).

.collapse('hide')

Kache yon eleman ki rabat. Retounen bay moun k ap rele a anvan yo te kache eleman ki rabat (sa vle di anvan hidden.bs.collapseevènman an rive).

.collapse('dispose')

Detwi efondreman yon eleman.

Evènman

Klas efondreman Bootstrap a ekspoze kèk evènman pou branche nan fonksyonalite efondreman.

Kalite Evènman Deskripsyon
montre.bs.effondreman Evènman sa a dife imedyatman lè yo showrele metòd egzanp lan.
montre.bs.effondreman Evènman sa a revoke lè yon eleman tonbe vin vizib pou itilizatè a (ap tann tranzisyon CSS yo fini).
kache.bs.effondreman Evènman sa a te tire imedyatman lè yo hidete rele metòd la.
hidden.bs.effondreman Evènman sa a revoke lè yon eleman tonbe kache nan men itilizatè a (ap tann pou tranzisyon CSS fini).
$('#myCollapsible').on('hidden.bs.collapse', function () {
  // do something...
})