SourceZotsitsa
Sinthani zokulirapo kuti muwonetse mndandanda wamaulalo ndi zina zambiri ndi pulogalamu yowonjezera ya Bootstrap.
Madontho otsika amatha kusinthika, ndikuwunjikana pazowonetsa mndandanda wamaulalo ndi zina zambiri. Amapangidwa kuti azilumikizana ndi pulogalamu yowonjezera ya JavaScript yophatikizidwa ya Bootstrap. Amasinthidwa ndikudina, osati kungoyang'ana; ichi ndi chisankho chopanga mwadala.
Zotsitsa zimamangidwa palaibulale ya anthu ena, Popper.js , yomwe imapereka mawonekedwe osinthika komanso kuzindikira malo owonera. Onetsetsani kuti mwaphatikiza popper.min.js pamaso pa Bootstrap's JavaScript kapena gwiritsani ntchito bootstrap.bundle.min.js
/ bootstrap.bundle.js
yomwe ili ndi Popper.js. Popper.js sichigwiritsidwa ntchito poyika zotsikira mu navbars ngakhale kuti kuyimitsidwa kosunthika sikofunikira.
Ngati mukupanga JavaScript yathu kuchokera kugwero, pamafunikautil.js
.
Muyezo wa WAI ARIA umatanthawuza role="menu"
widget yeniyeni , koma iyi ndi mindandanda yazantchito yomwe imayambitsa zochita kapena ntchito. Mindandanda ya ARIA imatha kukhala ndi menyu, zinthu zamabokosi, zinthu za batani la wailesi, magulu a batani la wailesi, ndi ma menyu ang'onoang'ono.
Zotsitsa za Bootstrap, kumbali ina, zidapangidwa kuti zikhale zanthawi zonse komanso zogwiritsidwa ntchito pazosiyanasiyana komanso mawonekedwe. Mwachitsanzo, ndizotheka kupanga zotsitsa zomwe zimakhala ndi zowonjezera ndi zowongolera mawonekedwe, monga malo osakira kapena mafomu olowera. Pazifukwa izi, Bootstrap sayembekezera (kapena kungowonjezera) chilichonse role
mwazofunikira pamamenyu aria-
enieni a ARIA . Olemba akuyenera kuphatikizirapo izi mwapadera iwo eni.
Komabe, Bootstrap imawonjezera chithandizo chokhazikika pazolumikizana zambiri zamakiyibodi, monga kutha kusuntha pazinthu .dropdown-item
zilizonse pogwiritsa ntchito makiyi a cholozera ndikutseka menyu ndi ESC kiyi.
Manga chosinthira chotsitsa (batani kapena ulalo wanu) ndi menyu yotsikira mkati .dropdown
, kapena chinthu china chomwe chimalengeza position: relative;
. Zotsitsa zitha kuyambika kuchokera <a>
kapena <button>
zinthu kuti zigwirizane ndi zosowa zanu.
Chilichonse .btn
chikhoza kusinthidwa kukhala chotsitsa chotsitsa ndi zosintha zina. Umu ndi momwe mungawagwiritsire ntchito ndi <button>
zinthu zilizonse:
Koperani
<div class= "dropdown" >
<button class= "btn btn-secondary dropdown-toggle" type= "button" id= "dropdownMenuButton" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropdown button
</button>
<div class= "dropdown-menu" aria-labelledby= "dropdownMenuButton" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
</div>
</div>
Ndipo ndi <a>
zinthu:
Koperani
<div class= "dropdown" >
<a class= "btn btn-secondary dropdown-toggle" href= "#" role= "button" id= "dropdownMenuLink" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropdown link
</a>
<div class= "dropdown-menu" aria-labelledby= "dropdownMenuLink" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
</div>
</div>
Gawo labwino kwambiri ndikuti mutha kuchita izi ndi batani lililonse, nanunso:
Pulayimale
Sekondale
Kupambana
Zambiri
Chenjezo
Ngozi
Koperani
<!-- Example single danger button -->
<div class= "btn-group" >
<button type= "button" class= "btn btn-danger dropdown-toggle" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Action
</button>
<div class= "dropdown-menu" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
<div class= "dropdown-divider" ></div>
<a class= "dropdown-item" href= "#" > Separated link</a>
</div>
</div>
Momwemonso, pangani zotsitsa za batani logawanika zokhala ndi chizindikiro chofanana ndi mabatani amodzi, koma ndikuwonjezera .dropdown-toggle-split
malo oyenera kuzungulira malo otsikira.
Timagwiritsa ntchito kalasi yowonjezerayi kuti tichepetse zopingasa padding
mbali zonse za chisamaliro ndi 25% ndikuchotsa margin-left
zomwe zimawonjezedwa pamakina otsika. Kusintha kowonjezerako kumapangitsa kuti chisamaliro chikhale chokhazikika mu batani logawanika ndikupereka malo ogunda moyenerera pafupi ndi batani lalikulu.
Pulayimale
Sinthani Kutsitsa
Sekondale
Sinthani Kutsitsa
Kupambana
Sinthani Kutsitsa
Zambiri
Sinthani Kutsitsa
Chenjezo
Sinthani Kutsitsa
Ngozi
Sinthani Kutsitsa
Koperani
<!-- Example split danger button -->
<div class= "btn-group" >
<button type= "button" class= "btn btn-danger" > Action</button>
<button type= "button" class= "btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
<span class= "sr-only" > Toggle Dropdown</span>
</button>
<div class= "dropdown-menu" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
<div class= "dropdown-divider" ></div>
<a class= "dropdown-item" href= "#" > Separated link</a>
</div>
</div>
Mabatani otsikirapo amagwira ntchito ndi mabatani amitundu yonse, kuphatikiza mabatani otsikirapo ndi ogawanika.
Koperani
<!-- Large button groups (default and split) -->
<div class= "btn-group" >
<button class= "btn btn-secondary btn-lg dropdown-toggle" type= "button" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Large button
</button>
<div class= "dropdown-menu" >
...
</div>
</div>
<div class= "btn-group" >
<button class= "btn btn-secondary btn-lg" type= "button" >
Large split button
</button>
<button type= "button" class= "btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
<span class= "sr-only" > Toggle Dropdown</span>
</button>
<div class= "dropdown-menu" >
...
</div>
</div>
<!-- Small button groups (default and split) -->
<div class= "btn-group" >
<button class= "btn btn-secondary btn-sm dropdown-toggle" type= "button" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Small button
</button>
<div class= "dropdown-menu" >
...
</div>
</div>
<div class= "btn-group" >
<button class= "btn btn-secondary btn-sm" type= "button" >
Small split button
</button>
<button type= "button" class= "btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
<span class= "sr-only" > Toggle Dropdown</span>
</button>
<div class= "dropdown-menu" >
...
</div>
</div>
Yambitsani mindandanda yotsikira pamwamba pa zinthu powonjezera .dropup
ku chinthu cha makolo.
Kusiya
Kugawanitsa dropup
Sinthani Kutsitsa
Koperani
<!-- Default dropup button -->
<div class= "btn-group dropup" >
<button type= "button" class= "btn btn-secondary dropdown-toggle" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropup
</button>
<div class= "dropdown-menu" >
<!-- Dropdown menu links -->
</div>
</div>
<!-- Split dropup button -->
<div class= "btn-group dropup" >
<button type= "button" class= "btn btn-secondary" >
Split dropup
</button>
<button type= "button" class= "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
<span class= "sr-only" > Toggle Dropdown</span>
</button>
<div class= "dropdown-menu" >
<!-- Dropdown menu links -->
</div>
</div>
Yambitsani mindandanda yotsikira kumanja kwa zinthu powonjezera .dropright
ku chinthu cha makolo.
Dropright
Kugawanika dropright
Sinthani Dropright
Koperani
<!-- Default dropright button -->
<div class= "btn-group dropright" >
<button type= "button" class= "btn btn-secondary dropdown-toggle" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropright
</button>
<div class= "dropdown-menu" >
<!-- Dropdown menu links -->
</div>
</div>
<!-- Split dropright button -->
<div class= "btn-group dropright" >
<button type= "button" class= "btn btn-secondary" >
Split dropright
</button>
<button type= "button" class= "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
<span class= "sr-only" > Toggle Dropright</span>
</button>
<div class= "dropdown-menu" >
<!-- Dropdown menu links -->
</div>
</div>
Yambitsani mindandanda yotsikira kumanzere kwa zinthu powonjezera .dropleft
ku chinthu cha makolo.
Dropleft
Sinthani Dropleft
Gawani kumanzere
Koperani
<!-- Default dropleft button -->
<div class= "btn-group dropleft" >
<button type= "button" class= "btn btn-secondary dropdown-toggle" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropleft
</button>
<div class= "dropdown-menu" >
<!-- Dropdown menu links -->
</div>
</div>
<!-- Split dropleft button -->
<div class= "btn-group" >
<div class= "btn-group dropleft" role= "group" >
<button type= "button" class= "btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
<span class= "sr-only" > Toggle Dropleft</span>
</button>
<div class= "dropdown-menu" >
<!-- Dropdown menu links -->
</div>
</div>
<button type= "button" class= "btn btn-secondary" >
Split dropleft
</button>
</div>
Zakale zomwe zatsikira pansi zidayenera kukhala maulalo, koma sizili choncho ndi v4. Tsopano mutha kugwiritsa ntchito <button>
zinthu pazotsitsa zanu m'malo mwa <a>
s basi.
Koperani
<div class= "dropdown" >
<button class= "btn btn-secondary dropdown-toggle" type= "button" id= "dropdownMenu2" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropdown
</button>
<div class= "dropdown-menu" aria-labelledby= "dropdownMenu2" >
<button class= "dropdown-item" type= "button" > Action</button>
<button class= "dropdown-item" type= "button" > Another action</button>
<button class= "dropdown-item" type= "button" > Something else here</button>
</div>
</div>
Mutha kupanganso zinthu zosagwiritsa ntchito potsitsa ndi .dropdown-item-text
. Khalani omasuka kuti muwonjezere mawonekedwe ndi CSS kapena zolemba.
Koperani
<div class= "dropdown-menu" >
<span class= "dropdown-item-text" > Dropdown item text</span>
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
</div>
Onjezani .active
kuzinthu zomwe zili m'munsi kuti ziwoneke ngati zikugwira ntchito .
Koperani
<div class= "dropdown-menu" >
<a class= "dropdown-item" href= "#" > Regular link</a>
<a class= "dropdown-item active" href= "#" > Active link</a>
<a class= "dropdown-item" href= "#" > Another link</a>
</div>
Onjezani .disabled
kuzinthu zomwe zili m'munsi kuti muzisanjire ngati zolephereka .
Koperani
<div class= "dropdown-menu" >
<a class= "dropdown-item" href= "#" > Regular link</a>
<a class= "dropdown-item disabled" href= "#" > Disabled link</a>
<a class= "dropdown-item" href= "#" > Another link</a>
</div>
Mwachikhazikitso, menyu yotsitsa imayikidwa 100% kuchokera pamwamba ndi kumanzere kwa kholo lake. Onjezani .dropdown-menu-right
ku a .dropdown-menu
kulumikiza kumanja menyu yotsitsa.
Mungodziwiratu! Zotsitsa zimayikidwa chifukwa cha Popper.js (kupatula ngati zili mu navbar).
Koperani
<div class= "btn-group" >
<button type= "button" class= "btn btn-secondary dropdown-toggle" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Right-aligned menu
</button>
<div class= "dropdown-menu dropdown-menu-right" >
<button class= "dropdown-item" type= "button" > Action</button>
<button class= "dropdown-item" type= "button" > Another action</button>
<button class= "dropdown-item" type= "button" > Something else here</button>
</div>
</div>
Onjezani mutu kuti mulembe magawo a zochita mu menyu yotsikira.
Koperani
<div class= "dropdown-menu" >
<h6 class= "dropdown-header" > Dropdown header</h6>
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
</div>
Olekanitsa magulu azinthu zokhudzana ndi menyu ndi chogawa.
Koperani
<div class= "dropdown-menu" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
<div class= "dropdown-divider" ></div>
<a class= "dropdown-item" href= "#" > Separated link</a>
</div>
Ikani mawu aliwonse aulere mkati mwa menyu otsika omwe ali ndi mawu ndikugwiritsa ntchito masitayilo . Dziwani kuti mudzafunika masitayelo owonjezera kuti muchepetse kukula kwa menyu.
Koperani
<div class= "dropdown-menu p-4 text-muted" style= "max-width: 200px;" >
<p>
Some example text that's free-flowing within the dropdown menu.
</p>
<p class= "mb-0" >
And this is more example text.
</p>
</div>
Ikani fomu mkati mwa menyu yotsitsa, kapena ipangitseni kukhala menyu yotsitsa, ndipo gwiritsani ntchito maginito kapena ma padding kuti mupatse malo omwe mukufuna.
Koperani
<div class= "dropdown-menu" >
<form class= "px-4 py-3" >
<div class= "form-group" >
<label for= "exampleDropdownFormEmail1" > Email address</label>
<input type= "email" class= "form-control" id= "exampleDropdownFormEmail1" placeholder= "[email protected] " >
</div>
<div class= "form-group" >
<label for= "exampleDropdownFormPassword1" > Password</label>
<input type= "password" class= "form-control" id= "exampleDropdownFormPassword1" placeholder= "Password" >
</div>
<div class= "form-check" >
<input type= "checkbox" class= "form-check-input" id= "dropdownCheck" >
<label class= "form-check-label" for= "dropdownCheck" >
Remember me
</label>
</div>
<button type= "submit" class= "btn btn-primary" > Sign in</button>
</form>
<div class= "dropdown-divider" ></div>
<a class= "dropdown-item" href= "#" > New around here? Sign up</a>
<a class= "dropdown-item" href= "#" > Forgot password?</a>
</div>
Koperani
<form class= "dropdown-menu p-4" >
<div class= "form-group" >
<label for= "exampleDropdownFormEmail2" > Email address</label>
<input type= "email" class= "form-control" id= "exampleDropdownFormEmail2" placeholder= "[email protected] " >
</div>
<div class= "form-group" >
<label for= "exampleDropdownFormPassword2" > Password</label>
<input type= "password" class= "form-control" id= "exampleDropdownFormPassword2" placeholder= "Password" >
</div>
<div class= "form-check" >
<input type= "checkbox" class= "form-check-input" id= "dropdownCheck2" >
<label class= "form-check-label" for= "dropdownCheck2" >
Remember me
</label>
</div>
<button type= "submit" class= "btn btn-primary" > Sign in</button>
</form>
Gwiritsani ntchito data-offset
kapena data-reference
kusintha malo otsitsa.
Koperani
<div class= "d-flex" >
<div class= "dropdown mr-1" >
<button type= "button" class= "btn btn-secondary dropdown-toggle" id= "dropdownMenuOffset" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" data-offset= "10,20" >
Offset
</button>
<div class= "dropdown-menu" aria-labelledby= "dropdownMenuOffset" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
</div>
</div>
<div class= "btn-group" >
<button type= "button" class= "btn btn-secondary" > Reference</button>
<button type= "button" class= "btn btn-secondary dropdown-toggle dropdown-toggle-split" id= "dropdownMenuReference" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" data-reference= "parent" >
<span class= "sr-only" > Toggle Dropdown</span>
</button>
<div class= "dropdown-menu" aria-labelledby= "dropdownMenuReference" >
<a class= "dropdown-item" href= "#" > Action</a>
<a class= "dropdown-item" href= "#" > Another action</a>
<a class= "dropdown-item" href= "#" > Something else here</a>
<div class= "dropdown-divider" ></div>
<a class= "dropdown-item" href= "#" > Separated link</a>
</div>
</div>
</div>
Pogwiritsa ntchito mawonekedwe a data kapena JavaScript, pulogalamu yowonjezera yotsitsa imasintha zobisika (mindandanda yotsikira) posintha .show
kalasiyo pamndandanda wa makolo. Lingaliroli data-toggle="dropdown"
limadaliridwa potseka mindandanda yazakudya pamlingo wogwiritsa ntchito, ndiye ndibwino kuti muzigwiritsa ntchito nthawi zonse.
Pazida zomwe zimagwira, kutsegula kutsika kumawonjezera zopanda kanthu ( $.noop
) zogwirira mouseover
ntchito kwa ana omwe ali nawo <body>
. Kuthyolako kovomerezeka kumeneku ndikofunikira kuti mugwiritse ntchito movutikira muutumiki wa zochitika za iOS , zomwe zingalepheretse kugunda kulikonse kunja kwa dontho kuti zisayambitse khodi yomwe imatseka kutsitsa. Kutsitsa kukatsekedwa, zowongolera zopanda kanthu mouseover
izi zimachotsedwa.
Kudzera muzochita za data
Onjezani data-toggle="dropdown"
ku ulalo kapena batani kuti musinthe kutsitsa.
Koperani
<div class= "dropdown" >
<button id= "dLabel" type= "button" data-toggle= "dropdown" aria-haspopup= "true" aria-expanded= "false" >
Dropdown trigger
</button>
<div class= "dropdown-menu" aria-labelledby= "dLabel" >
...
</div>
</div>
Imbani zotsitsa kudzera pa JavaScript:
Koperani
$ ( '.dropdown-toggle' ). dropdown ()
data-toggle="dropdown"
zofunikabe
Mosasamala kanthu kuti mumayitanira kutsika kwanu kudzera pa JavaScript kapena m'malo mwake mugwiritse ntchito data-api, data-toggle="dropdown"
nthawi zonse imafunika kuti mukhalepo pazoyambitsa zotsitsa.
Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-
, monga mu data-offset=""
.
Dzina
Mtundu
Zosasintha
Kufotokozera
kuchepetsa
nambala | chingwe | ntchito
0
Kuchotsera kwa dontho lotsika poyerekeza ndi chandamale chake. Kuti mumve zambiri onani za Popper.js's offset docs .
tembenuza
boolean
zoona
Lolani Dropdown itembenuke ngati pakhala palimodzi pagawo lolozera. Kuti mumve zambiri onani za Popper.js's flip docs .
malire
chingwe | chinthu
'scrollParent'
Malire oletsa kusefukira a menyu otsika. Imavomereza mfundo za 'viewport'
, 'window'
, 'scrollParent'
, kapena HTMLElement reference (JavaScript yokha). Kuti mudziwe zambiri onani zolemba za preventOverflow za Popper.js .
umboni
chingwe | chinthu
'kusintha'
Cholozera cha menyu otsika. Imavomereza mfundo za 'toggle'
, 'parent'
, kapena HTMLElement reference. Kuti mudziwe zambiri onani zolemba za Popper.js's referenceObject docs .
chiwonetsero
chingwe
'dynamic'
Mwachikhazikitso, timagwiritsa ntchito Popper.js poyika ma dynamic positioning. Letsani izi ndi static
.
Zindikirani pamene boundary
akhazikitsidwa ku mtengo wina uliwonse kupatulapo 'scrollParent'
, kalembedwe kameneka position: static
kamagwiritsidwa ntchito pa .dropdown
chidebecho.
Njira
Kufotokozera
$().dropdown('toggle')
Imatembenuza menyu yotsikira ya navbar yopatsidwa kapena kusakatula kwa tabu.
$().dropdown('update')
Imawonjezera pomwe pali kutsika kwa chinthu.
$().dropdown('dispose')
Imawononga kutsika kwa chinthu.
Zochitika zonse zotsikira zimathamangitsidwa ku .dropdown-menu
's kholo element ndipo zimakhala ndi relatedTarget
katundu, zomwe mtengo wake ndi toggling nangula element. hide.bs.dropdown
ndipo hidden.bs.dropdown
zochitika zimakhala ndi clickEvent
katundu (pokhapo pamene mtundu wa chochitika choyambirira uli click
) chomwe chili ndi Chochitika Chochitika cha chochitikacho.
Chochitika
Kufotokozera
show.bs.dropdown
Chochitika ichi chimayaka nthawi yomweyo njira yachiwonetsero imatchedwa.
shown.bs.dropdown
Chochitikachi chimachotsedwa pamene kutsika kwawonekera kwa wogwiritsa ntchito (kudikira kusintha kwa CSS, kuti kumalize).
hide.bs.dropdown
Chochitikachi chimachotsedwa nthawi yomweyo njira yobisala itayitanidwa.
hidden.bs.dropdown
Chochitikachi chimachotsedwa pamene dontho latha kubisidwa kwa wogwiritsa ntchito (kudikira kusintha kwa CSS, kuti kumalize).
Koperani
$ ( '#myDropdown' ). on ( 'show.bs.dropdown' , function () {
// do something…
})