Svetuka kune chikuru content Svetuka kuenda kudocs navigation
in English

Collapse

Shandura kuoneka kwezviri mukati meprojekiti yako nemakirasi mashoma uye yedu JavaScript plugins.

Zvinoshanda sei

Iyo yekuputsika JavaScript plugin inoshandiswa kuratidza nekuviga zvirimo. Mabhatani kana zvibatiso zvinoshandiswa sezvinokonzeresa zvakamisikidzwa kune chaiwo zvinhu zvaunoshandura. Kupeta chinhu kuno raramisa heightkubva pakukosha kwayo kuenda ku 0. Tichifunga kuti CSS inobata sei mifananidzo, haugone kushandisa paddingpane .collapsechinhu. Pane kudaro, shandisa kirasi sechinhu chakazvimirira chekuputira chinhu.

Iyo animation mhedzisiro yechikamu ichi zvinoenderana prefers-reduced-motionnemubvunzo wenhau. Ona chikamu chakaderedzwa chezvinyorwa zvedu zvekusvikika .

Muenzaniso

Dzvanya mabhatani ari pazasi kuratidza uye kuviga chimwe chinhu kuburikidza nekuchinja kwekirasi:

  • .collapseanovanza zviri mukati
  • .collapsinginoshandiswa panguva yekuchinja
  • .collapse.showinoratidza zvirimo

Kazhinji, tinokurudzira kushandisa bhatani rine data-bs-targethunhu. Kunyange zvisingakurudzirwe kubva pakuona semantic, unogona zvakare kushandisa chinongedzo chine hrefhunhu (uye a role="button"). Muzviitiko zvose izvi, data-bs-toggle="collapse"zvinodiwa.

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-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
    Link with href
  </a>
  <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
    Button with data-bs-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>

Horizontal

Iyo yekudonha plugin zvakare inotsigira yakachinjika kudonha. Wedzera iyo .collapse-horizontalmodifier kirasi kuti uchinje iyo widthpachinzvimbo heightuye isa widthpane yezvino mwana chinhu. Inzwa wakasununguka kunyora yako wega tsika Sass, shandisa inline masitaera, kana kushandisa yedu yehupamhi zvishandiso .

Ndokumbira utarise kuti nepo muenzaniso uri pazasi uine min-heightseti yekudzivirira yakawandisa repaint mumagwaro edu, izvi hazvidiwe zvakajeka. Chete widthpane chinhu chemwana chinodiwa.

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-bs-toggle="collapse" data-bs-target="#collapseWidthExample" aria-expanded="false" aria-controls="collapseWidthExample">
    Toggle width collapse
  </button>
</p>
<div style="min-height: 120px;">
  <div class="collapse collapse-horizontal" id="collapseWidthExample">
    <div class="card card-body" style="width: 300px;">
      This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
    </div>
  </div>
</div>

Zvinangwa zvakawanda

A <button>kana <a>inogona kuratidza uye kuvanza zvinhu zvakawanda nekuzvirevera neanosarudza mune ayo hrefkana data-bs-targethunhu. Yakawanda <button>kana <a>inogona kuratidza uye kuvanza chinhu kana mumwe nemumwe akachinongedzera nechavo hrefkana data-bs-targethunhu

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-bs-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1">Toggle first element</a>
  <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">Toggle second element</button>
  <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-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>

Accessibility

Iva nechokwadi chekuwedzera aria-expandedkune chekutonga chinhu. Uhwu hunhu hunoburitsa zviripachena mamiriro azvino echinhu chinokorokoka chakasungirirwa pakutonga kuvaverengi vezvikirini uye mamwe matekinoroji ekubatsira. Kana iyo chinhu chinoputika chakavharwa nekusagadzika, hunhu huri pane chekutonga hunofanirwa kuve nehukoshi hwe aria-expanded="false". Kana iwe wakaseta chinhu chinoputika kuti chivhurwe nekusarudzika uchishandisa showkirasi, isa aria-expanded="true"pane control pane. Iyo plugin inozochinja otomatiki hunhu uhu pahutongi zvichibva pakuti kana chinhu chinokorokoka chavhurwa kana kuvharwa (kuburikidza neJavaScript, kana nekuti mushandisi akonzeresa chimwe chinhu chekudzora chakasungirirwa kune chimwe chinhu chinoputika). Kana iyo control element's HTML element isiri bhatani (semuenzaniso, an <a>kana <div>), hunhurole="button"inofanira kuwedzerwa kune element.

Kana chinhu chako chekutonga chiri kunanga chinhu chimwe chinoputsika - kureva kuti data-bs-targethunhu huri kunongedza kune imwe idsarudzo - iwe unofanirwa kuwedzera aria-controlshunhu kuchinhu chekutonga, chine idchechinhu chinodonha. Vaverengi vemazuva ano skrini uye matekinoroji ekubatsira akafanana anoshandisa hunhu uhwu kupa vashandisi mamwe mapfupi ekufamba akananga kuchinhu chinoputika pachacho.

Ziva kuti kuita kwazvino kweBootstrap hakuvharidzire kupindirana kwakasiyana-siyana kwekiibhodhi kunotsanangurwa muWAI-ARIA Maitiro eVanyori 1.1 accordion pateni - unozofanirwa kusanganisa iwe pachako neJavaScript.

Sass

Variables

$transition-collapse:         height .35s ease;
$transition-collapse-width:   width .35s ease;

Makirasi

Kupunza makirasi eshanduko anogona kuwanikwa mukati scss/_transitions.scsssezvo aya akagovaniswa muzvikamu zvakawanda (kudonha uye accordion).

.collapse {
  &:not(.show) {
    display: none;
  }
}

.collapsing {
  height: 0;
  overflow: hidden;
  @include transition($transition-collapse);

  &.collapse-horizontal {
    width: 0;
    height: auto;
    @include transition($transition-collapse-width);
  }
}

Usage

Iyo yekudonha plugin inoshandisa mashoma makirasi kubata inorema kusimudza:

  • .collapseinovanza zviri mukati
  • .collapse.showinoratidza zviri mukati
  • .collapsinginowedzerwa kana shanduko yatanga, uye inobviswa kana yapera

Aya makirasi anogona kuwanikwa mu _transitions.scss.

Via data hunhu

Ingo wedzera data-bs-toggle="collapse"uye a data-bs-targetkune chinhu kuti ugozvigadzike kutonga kwechimwe kana kupfuura chinodonha zvinhu. Hunhu data-bs-targethunogamuchira CSS selector yekushandisa iyo kuputsika. Iva nechokwadi chekuwedzera kirasi collapsekune chinhu chinoputika. Kana uchida kuti risavhurika, wedzera imwe kirasi show.

Kuwedzera accordion-senge boka manejimendi munzvimbo inoputsika, wedzera iyo data hunhu data-bs-parent="#selector". Tarisa kune accordion peji kuti uwane rumwe ruzivo.

Via JavaScript

Vhura nemaoko ne:

var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
var collapseList = collapseElementList.map(function (collapseEl) {
  return new bootstrap.Collapse(collapseEl)
})

Options

Sarudzo dzinogona kupfuudzwa kuburikidza nedata hunhu kana JavaScript. Nezve data hunhu, wedzera iyo sarudzo zita ku data-bs-, semu data-bs-parent="".

Zita Type Default Tsanangudzo
parent selector | jQuery chinhu | DOM chikamu false Kana mubereki apihwa, zvese zvinopeta pasi pemubereki wataurwa zvichavharwa kana chinhu chinopetana ichi charatidzwa. (zvakafanana nemaitiro echinyakare accordion - izvi zvinoenderana cardnekirasi). Hunhu hunofanirwa kuiswa panzvimbo inoputsika.
toggle boolean true Inoshandura chinhu chinopeta pakukumbira

Nzira

Asynchronous nzira uye shanduko

Yese nzira dzeAPI dzine asynchronous uye dzinotanga shanduko . Vanodzokera kumunhu anenge afona pachangotanga shanduko asi isati yapera . Pamusoro pezvo, kufona kwenzira pachikamu chekuchinja kuchafuratirwa .

Ona zvinyorwa zvedu zveJavaScript kuti uwane rumwe ruzivo .

Inobatisa zvirimo sechinhu chinogoneka. Inobvuma sarudzo dzaungada object.

Iwe unogona kugadzira yekudonha muenzaniso nemugadziri, semuenzaniso:

var myCollapse = document.getElementById('myCollapse')
var bsCollapse = new bootstrap.Collapse(myCollapse, {
  toggle: false
})
Nzira Tsanangudzo
toggle Inoshandura chinhu chinopeta kuti chiratidze kana kuvanzwa. Inodzokera kune ari kufona chinhu chinopeta chisati charatidzwa kana kuvanzwa (kureva kuti shown.bs.collapsekana hidden.bs.collapsechiitiko chisati chaitika).
show Inoratidza chinhu chinopeta. Inodzokera kumunhu arikufona chinhu chinopeta chisati chanyatsoratidzwa (semuenzaniso, shown.bs.collapsechiitiko chisati chaitika).
hide Inoviga chinhu chinopeta. Inodzokera kumunhu arikufona chinhu chinopeta chisati chavanzwa (semuenzaniso, hidden.bs.collapsechiitiko chisati chaitika).
dispose Inoparadza kuputsika kwechimwe chinhu. (Inobvisa data rakachengetwa pachinhu cheDOM)
getInstance Static nzira iyo inokutendera iwe kuti uwane iyo yekudonha muenzaniso yakabatana neiyo DOM chinhu, unogona kuishandisa seizvi:bootstrap.Collapse.getInstance(element)
getOrCreateInstance Static nzira inodzosa chiitiko chekudonha chakabatana nechinhu cheDOM kana kugadzira chitsva kana chisina kutangwa. Unogona kuishandisa seizvi:bootstrap.Collapse.getOrCreateInstance(element)

Zviitiko

Bootstrap's kudonha kirasi inofumura zviitiko zvishoma zvekukochekera mukudonha kushanda.

Chiitiko mhando Tsanangudzo
show.bs.collapse Ichi chiitiko chinopisa nekukasira kana shownzira yemuenzaniso inodanwa.
shown.bs.collapse Ichi chiitiko chinodzingwa kana chinhu chekudonha chaitwa kuti chionekwe kumushandisi (chinomirira kuti CSS shanduko ipedze).
hide.bs.collapse Chiitiko ichi chinodzingwa pakarepo kana hidenzira yadaidzwa.
hidden.bs.collapse Chiitiko ichi chinodzingwa kana chinhu chekudonha chakavanzwa kubva kumushandisi (chinomirira kuti CSS shanduko ipedze).
var myCollapsible = document.getElementById('myCollapsible')
myCollapsible.addEventListener('hidden.bs.collapse', function () {
  // do something...
})