Ku wa
Cinca ku vonaka ka swilo leswi nga endzeni eka phurojeke ya wena hinkwayo hi titlilasi ti nga ri tingani na swiengetelo swa hina swa JavaScript.
Ndlela leyi swi tirhaka ha yona
Plugin ya JavaScript ya collapse yi tirhisiwa ku kombisa na ku fihla leswi nga endzeni. Tiboto kumbe ti- anchor ti tirhisiwa tanihi swihlohloteri leswi mepiweke eka swiaki swo karhi leswi u swi cinca-cincaka. Ku pfotlosa elemente swi ta endla leswaku ku hanya ku height
suka eka ntikelo wa yona wa sweswi ku ya eka 0
. Loko u nyikiwa ndlela leyi CSS yi khomaka swifaniso leswi hanyaka ha yona, a wu nge swi koti ku tirhisa padding
eka .collapse
elemente. Ematshan’weni ya sweswo, tirhisa tlilasi tanihi xiaki xo phutsela lexi tiyimeleke.
prefers-reduced-motion
xivutiso xa midiya. Vona
xiyenge xa ku famba loku hungutiweke xa matsalwa ya hina ya ku fikelela .
Xikombiso
Click ti buttons leti nga laha hansi ku kombisa no fihla element yin’wana hi ku tirhisa ku cinca ka class:
.collapse
yi fihla leswi nga endzeni.collapsing
yi tirhisiwa hi nkarhi wa ku cinca.collapse.show
yi kombisa leswi nga endzeni
Hi ntolovelo, hi ringanyeta ku tirhisa buti leyi nga ni data-target
xihlawulekisi. Hambileswi swi nga bumabumeriwiki hi ku ya hi langutelo ra semantiki, u nga ha tlhela u tirhisa xihlanganisi lexi nga ni href
xihlawulekisi (na a role="button"
). Eka swiyimo leswimbirhi, ku data-toggle="collapse"
laveka the.
<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>
Ololoka
Plugin ya ku wa yi tlhela yi seketela ku wa ka horizontal. Engetelani .width
tlilasi ya mucinci ku hundzula width
ematshan’wini ya height
na ku veka a width
eka elemente ya n’wana wa le kusuhi. Titwele u ntshunxekile ku tsala Sass ya wena ya ntolovelo, tirhisa switayele swa le ndzeni ka layini, kumbe u tirhisa switirhisiwa swa hina swa ku anama .
min-height
sete yo papalata ku penda nakambe ku tlula mpimo eka ti-doc ta hina, leswi a swi laveki hi ku kongoma.
Ku laveka ntsena width
elemente ya on the child.
<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>
Swikongomiso swo tala
A <button>
kumbe <a>
yi nga kombisa no fihla swiaki swo tala hi ku swi kombetela hi xihlawulekisi xa JQuery eka xihlawulekisi xa yona href
kumbe data-target
. Multiple <button>
kumbe <a>
va nga kombisa no tumbeta elemente loko un’wana na un’wana a yi kombetela hi yona href
kumbe data-target
attribute
<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>
Xikombiso xa accordion
Hi ku tirhisa xiphemu xa khadi , u nga engetela mahanyelo ya ku wisa ya ntolovelo leswaku u endla accordion. Leswaku u fikelela kahle xitayili xa accordion, tiyiseka leswaku u xi tirhisa .accordion
tanihi xifunengeto.
.show
tlilasi.
<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>
Ku fikelela
Tiyisisa leswaku u engetela aria-expanded
eka xiaki xa vulawuri. Xihlawulekisi lexi xi hundzisela hi ku kongoma xiyimo xa sweswi xa xiaki lexi pfotlosaka lexi bohiweke eka vulawuri eka vahlayi va xikirini na thekinoloji yo pfuneta yo fana. Loko xiaki lexi nga pfaleriwaka xi pfariwile hi ku tiyimisela, xihlawulekisi eka xiaki xa vulawuri xi fanele ku va na ntikelo wa aria-expanded="false"
. Loko u vekile elemente leyi nga pfaleriwaka leswaku yi pfuleka hi ku tiyimisela hi ku tirhisa show
tlilasi, veka aria-expanded="true"
eka vulawuri ematshan’wini ya sweswo. Plugin yi ta cinca-cinca hi yoxe xihlawulekisi lexi eka vulawuri hi ku ya hi loko kumbe e-e xiaki lexi nga pfaleriwaka xi pfuriwile kumbe ku pfariwa (hi ku tirhisa JavaScript, kumbe hikuva mutirhisi u pfuxe xiaki xin’wana xa vulawuri lexi na xona xi bohiweke eka xiaki lexi fanaka lexi pfaleriwaka). Loko xiaki xa HTML xa xiaki xa vulawuri xi nga ri buti (xikombiso, an <a>
kumbe <div>
), xihlawulekisirole="button"
yi fanele ku engeteriwa eka elemente.
Loko xiaki xa wena xa vulawuri xi kongomisa eka xiaki xin’we lexi nga pfaleriwaka – i.e. data-target
xihlawulekisi xi kombetela eka id
xihlawulekisi – u fanele ku engetela aria-controls
xihlawulekisi eka xiaki xa vulawuri, lexi nga na id
xa xiaki lexi pfaleriwaka. Swihlaya swa xikirini swa manguva lawa na thekinoloji yo pfuneta leyi fanaka swi tirhisa xihlawulekisi lexi ku nyika vatirhisi swipfuxeto leswi engetelekeke swo famba hi ku kongoma eka xiaki lexi nga pfaleriwaka hi xoxe.
Xiya leswaku ku tirhisiwa ka sweswi ka Bootstrap a ku katsi ku tirhisana ko hambana ka khibhodi loku hlamuseriweke eka xivumbeko xa accordion xa ARIA Authoring Practices Guide - u ta lava ku katsa leswi hi wexe hi JavaScript ya ntolovelo.
Matirhiselo
Plugin ya ku wa yi tirhisa titlilasi ti nga ri tingani ku khoma ku tlakusa swilo swo tika:
.collapse
yi fihla leswi nga endzeni.collapse.show
yi kombisa leswi nga endzeni.collapsing
yi engeteriwa loko ku cinca ku sungula, naswona yi susiwa loko ku herile
Titlilasi leti ti nga kumeka eka _transitions.scss
.
Hi ku tirhisa swihlawulekisi swa data
Ntsena engetela data-toggle="collapse"
na a data-target
eka elemente ku avela hi ku tisungulela vulawuri bya elemente yin’we kumbe ku tlula leyi nga tshovekaka. Xihlawulekisi data-target
xi amukela xihlawulekisi xa CSS ku tirhisa ku wisa eka xona. Tiyiseka leswaku u engetela tlilasi collapse
eka xiaki lexi nga pfaleriwaka. Loko u lava leswaku yi pfuleka hi ku tiyimisela, engetela tlilasi leyi engetelekeke show
.
Ku engetela vulawuri bya ntlawa lebyi fanaka ni bya accordion eka ndhawu leyi nga pfaleriwaka, engetela xihlawulekisi xa data data-parent="#selector"
. Languta eka demo ku vona leswi swi ri karhi swi tirha.
Hi ku tirhisa JavaScript
Endla leswaku swi tirha hi voko hi:
$('.collapse').collapse()
Swihlawulekisi
Swihlawulekisi swi nga hundzisiwa hi ku tirhisa swihlawulekisi swa data kumbe JavaScript. Eka swihlawulekisi swa datha, engetela vito ra xihlawuhlawu eka data-
, tanihi le ka data-parent=""
.
Vito | Muxaka | Ku tlula | Nhlamuselo |
---|---|---|---|
mutswari | xihlawulekisi xa swilo | jNchumu wa xivutiso | Xiphemu xa DOM | vunwa | Loko mutswari a nyikiwile, kutani swiaki hinkwaswo leswi pfaleriwaka ehansi ka mutswari loyi a boxiweke swi ta pfala loko nchumu lowu wu pfaleriwaka wu kombisiwa. (ku fana na mahanyelo ya ndhavuko ya accordion - leswi swi titshege hi card tlilasi). Xihlawulekisi xi fanele ku vekiwa eka ndhawu leyi kongomisiweke leyi nga pfaleriwaka. |
ku cinca-cinca | xitsonga xitsonga | ntiyiso | Ku cinca-cinca xiaki lexi nga pfaleriwaka eka ku vitaniwa |
Maendlelo
Maendlelo ya asynchronous na ku cinca
Maendlelo hinkwawo ya API i ya asynchronous naswona ya sungula ku cinca . Va tlhelela eka mufoyini hi ku hatlisa loko ku cinca ku sungurile kambe ku nga si hela . Ku engetela kwalaho, ku vitaniwa ka ndlela eka xiphemu lexi cincaka ku ta honisiwa .
Vona matsalwa ya hina ya JavaScript ku kuma vuxokoxoko byo tala .
.collapse(options)
Ku endla leswaku nhundzu ya wena yi tirha tanihi xiaki lexi nga pfaleriwaka. Ku amukela swihlawulekisi swa ku hlawula object
.
$('#myCollapsible').collapse({
toggle: false
})
.collapse('toggle')
Ku cinca-cinca xiaki lexi nga pfaleriwaka ku ya eka lexi kombisiweke kumbe lexi fihliweke. Ku tlhelela eka mufoyini xiaki lexi nga pfaleriwaka xi nga si kombisiwa hakunene kumbe ku fihliwa (i.e. emahlweni ka ku humelela shown.bs.collapse
kumbe hidden.bs.collapse
xiendlakalo).
.collapse('show')
Ku kombisa xiaki lexi nga tshovekaka. Ku tlhelela eka mufoyini xiaki lexi nga pfaleriwaka xi nga si kombisiwa hakunene (i.e. shown.bs.collapse
xiendlakalo xi nga si humelela).
.collapse('hide')
Ku tumbeta xiaki lexi nga tshovekaka. Ku tlhelela eka mufoyini xiaki lexi nga pfaleriwaka xi nga si fihliwa hakunene (i.e. hidden.bs.collapse
xiendlakalo xi nga si humelela).
.collapse('dispose')
Ku herisa ku wa ka elemente.
Swiendlakalo
Tlilasi ya ku wa ya Bootstrap yi paluxa swiendlakalo swi nga ri swingani swo khoma eka ntirho wa ku wa.
Muxaka wa Xiendlakalo | Nhlamuselo |
---|---|
kombisa.bs.ku wa | Xiendlakalo lexi xi pfurha hi ku hatlisa loko ku show vitaniwa ndlela ya xikombiso. |
swi kombisiwile.bs.collapse | Xiendlakalo lexi xi duvuriwa loko xiphemu xa ku wa xi endliwile xi vonaka eka mutirhisi (xi ta rindza ku cinca ka CSS ku hetisisiwa). |
fihla.bs.ku pfula | Xiendlakalo lexi xi duvuriwa hi ku hatlisa loko hide ndlela yi vitaniwile. |
ku fihliwile.bs.ku wisa | Xiendlakalo lexi xi duvuriwa loko xiphemu xa ku wa xi fihliwile eka mutirhisi (xi ta rindza ku cinca ka CSS ku hela). |
$('#myCollapsible').on('hidden.bs.collapse', function () {
// do something...
})