SourceUkwehla
Guqula umxholo wokwaleka ukuze ubonise uluhlu lwamakhonkco kunye nokunye kunye ne-Bootstrap yokuhla iplagi.
Isishwankathelo
Ukwehla kuyatshintsheka, ukwaleka ngokomxholo wokubonisa uluhlu lwamakhonkco kunye nokunye. Zenziwe ukuba zisebenze kunye ne-Bootstrap yokuhla iplagi yeJavaScript. Ziguqulwa ngokucofa, hayi ngokushukuma; esi sisigqibo soyilo ngabom .
Iidrophu zakhiwe kwithala leencwadi lesithathu, iPopper.js , ebonelela ngokuma okuguquguqukayo kunye nokubonwa kwendawo yokujonga. Qinisekisa ukuquka i -popper.min.js phambi kweJavaScript yeBootstrap okanye usebenzise bootstrap.bundle.min.js
/ bootstrap.bundle.js
equlethe iPopper.js. I-Popper.js ayisetyenziswanga ukubeka ukwehla kwii-navbar nangona kungafuneki indawo eguqukayo.
Ukuba wakha iJavaScript yethu kwimvelaphi, kufunautil.js
.
Ukufikeleleka
Umgangatho we WAI ARIA uchaza role="menu"
iwijethi yokwenyani , kodwa oku kukodwa kwisicelo-njengemenu ezixhokonxa iintshukumo okanye imisebenzi. Iimenyu zeARIA zinokuqulatha kuphela izinto zemenyu, izinto zemenyu yebhokisi yokukhangela, izinto zemenyu yeqhosha lerediyo, amaqela amaqhosha erediyo, kunye neemenyu ezisezantsi.
I-Bootstrap's dropdowns, kwelinye icala, yenzelwe ukuba ibe yegeneric kwaye isebenze kwiimeko ezahlukeneyo kunye nezakhiwo zokuphawula. Umzekelo, kuyenzeka ukuba wenze izinto eziwa phantsi eziqulathe amagalelo awongezelelweyo kunye nolawulo lwefom, njengemimandla yokukhangela okanye iifom zokungena. Ngesi sizathu, iBootstrap ayilindelanga (okanye yongeze ngokuzenzekelayo) nayiphi na role
kunye aria-
neempawu ezifunekayo kwiimenyu zokwenyani zeARIA . Ababhali kuya kufuneka babandakanye ezi mpawu zithe ngqo ngokwabo.
Nangona kunjalo, i-Bootstrap iyongeza inkxaso eyakhelwe-ngaphakathi kunxibelelwano lwemenyu yebhodi yezitshixo eqhelekileyo, njengokukwazi ukuhamba .dropdown-item
kwizinto ezizimeleyo usebenzisa izitshixo zekhesa kwaye uvale imenyu ESCngesitshixo.
Imizekelo
Gqibezela itoggle yokwehla (iqhosha lakho okanye ikhonkco) kunye nemenyu eyehlayo ngaphakathi .dropdown
, okanye enye into ebhengeza position: relative;
. Ukwehla kunokuvuswa ukusuka <a>
okanye <button>
izinto ukuze zilungele iimfuno zakho ezinokubakho.
Nayiphi na enye .btn
ingajikwa ibe yidropdown toggle nolunye utshintsho lophawulo. Nantsi indlela onokuthi uzisebenzise ngayo naziphi na <button>
izinto:
Kwaye kunye <a>
nezinto:
Elona candelo lilungileyo ungakwenza oku ngalo naluphi na uhlobo lweqhosha, nalo:
Ngokukwanjalo, yenza iqhosha elicandiweyo elehlayo elinophawu olufanayo njengokwehla kweqhosha elinye, kodwa ngokongezwa .dropdown-toggle-split
kwesithuba esifanelekileyo esijikeleze ukhathalelo lokuhla.
Sisebenzisa olu didi longeziweyo ukunciphisa okuthe tyaba padding
macala omabini ekhathalelo ngama-25% kwaye sisuse margin-left
oko kongezwe kumaqhosha asezantsi. Olo tshintsho olongezelelweyo lugcina i-caret igxile kwiqhosha lokwahlula kwaye unikeze indawo yokubetha ngokufanelekileyo ngokufanelekileyo ecaleni kweqhosha eliphambili.
Ubungakanani
Amaqhosha okwehlayo asebenza ngamaqhosha abo bonke ubukhulu, kubandakanywa ukungagqibekanga kunye namaqhosha okulahla.
Izalathiso
Ukulahla
Qalisa imenyu eyehlayo ngentla kweziqalelo ngokongeza .dropup
kwinto engumzali.
I-Dropright
Qalisa imenyu eyehlayo ekunene kwezinto ngokongeza .dropright
kwinto engumzali.
I-Dropleft
Qalisa imenyu eyehlayo ekhohlo kwizinto ngokongeza .dropleft
kwinto engumzali.
Ngokwembali imixholo yemenyu eyehlayo bekufuneka ibe ngamakhonkco, kodwa ayisenjalo nge-v4. Ngoku ungakhetha ukusebenzisa <button>
izinto kokwehla kwakho endaweni ye- <a>
s nje.
Unako kwakhona ukwenza izinto zokuhla ezingasebenziyo nge .dropdown-item-text
. Zive ukhululekile ukwenza isitayile ngakumbi ngeCSS yesiko okanye izinto ezisetyenzisiweyo zokubhaliweyo.
Iyasebenza
Yongeza .active
kwizinto ezikuluhlu olusezantsi ukuze zizitayile njengezisebenzayo .
Kukhubazekile
Yongeza .disabled
kwizinto ezikuluhlu olusezantsi ukuze uzibhale njengezicinyiweyo .
Ngokungagqibekanga, imenyu eyehlayo ibekwa ngokuzenzekelayo nge-100% ukusuka phezulu kunye necala lasekhohlo lomzali wayo. Yongeza .dropdown-menu-right
ku-a .dropdown-menu
ukuya ekunene lungelelanisa imenyu eyehlayo.
Iintloko phezulu! Iidrophu phantsi zibekwe enkosi kwi-Popper.js (ngaphandle kokuba ziqulethwe kwi-navbar).
Ulungelelwaniso oluphendulayo
Ukuba ufuna ukusebenzisa ulungelelwaniso oluphendulayo, khubaza indawo eguqukayo ngokudibanisa data-display="static"
uphawu kwaye usebenzise iiklasi zokwahluka eziphendulayo.
Ukulungelelanisa ekunene imenyu eyehlayo kunye nendawo yokuphumla enikiweyo okanye enkulu, yongeza .dropdown-menu{-sm|-md|-lg|-xl}-right
.
Ukulungelelanisa ekhohlo imenyu eyehlayo kunye nendawo yoqhawulo enikiweyo okanye enkulu, yongeza .dropdown-menu-right
kunye .dropdown-menu{-sm|-md|-lg|-xl}-left
.
Qaphela ukuba awudingi kongeza data-display="static"
uphawu loyelelwano kumaqhosha okwehla kwii navbar, kuba iPopper.js ingasetyenziswa kwiinavbar.
Yongeza iheader ukulebhelisha amacandelo ezenzo kuyo nayiphi na imenyu eyehlayo.
Abahluli
Yahlula amaqela ezinto zemenyu ezinxulumeneyo kunye nesahluli.
Isicatshulwa
Beka nasiphi na isicatshulwa esikhululekileyo kwimenyu eyehlayo ngokubhaliweyo kwaye usebenzise izithuba eziluncedo . Qaphela ukuba uya kufuna izimbo zokulinganisa ezongezelelweyo ukunyanzela ububanzi bemenyu.
Faka ifom ngaphakathi kwemenyu eyehlayo, okanye uyenze ibe yimenyu eyehlayo, kwaye usebenzise i -margin okanye i-padding eziluncedo ukuyinika indawo engalunganga oyifunayo.
Iinketho zokwehla
Sebenzisa data-offset
okanye data-reference
utshintshe indawo yokwehla.
Ukusetyenziswa
Ngeempawu zedatha okanye iJavaScript, iplagin eyehlayo iguqula umxholo ofihliweyo (imenyu eyehlayo) ngokuguqula .show
iklasi kwizinto zoluhlu lwabazali. Uphawu data-toggle="dropdown"
loyelelwano kuthenjelwe kulo ukuvala imenyu eyehlayo kwinqanaba lesicelo, ngoko luluvo oluhle ukusoloko uyisebenzisa.
Kwizixhobo ezisebenza ngokuchukumisa, ukuvula i dropdown yongeza engenanto ( $.noop
) mouseover
abaphathi kubantwana <body>
abasondeleyo bento. Oku kuvunyiweyo ukuba kubi kwe-Hack kuyafuneka ukusebenza malunga ne- quirk kwi-iOS' abathunywa besiganeko , ebenokuthi ngenye indlela ithintele itephu naphi na ngaphandle kokwehla ekuqaliseni ikhowudi evala ukuhla. Nje ukuba idropdown ivaliwe, ezi zibambi zongezelelweyo ezingenanto mouseover
ziyasuswa.
Ngeempawu zedatha
Yongeza data-toggle="dropdown"
kwikhonkco okanye iqhosha ukuguqula ukwehla.
NgeJavaScript
Fowunela ukwehla ngeJavaScript:
data-toggle="dropdown"
isafuneka
Nokuba ufowunela ukwehla kwakho ngeJavaScript okanye endaweni yoko usebenzise i-data-api, data-toggle="dropdown"
isoloko ifuneka ukuba ubekhona kwindawo yokuqalisa ukwehla.
Iinketho
Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-
, njengakwi data-offset=""
.
Igama |
Uhlobo |
Ukuhlala kukho |
Inkcazo |
i-offset |
inombolo | umtya | umsebenzi |
0 |
I-offset yokuhla xa ithelekiswa nethagethi yayo. Xa umsebenzi usetyenziselwa ukumisela i-offset, ubizwa ngento equlethe idatha ye-offset njengengxabano yayo yokuqala. Umsebenzi kufuneka ubuyisele into enesakhiwo esifanayo. Isiqalo se-DOM node sigqithiselwe njengengxoxo yesibini. Ngolwazi oluthe kratya jonga kwi-Popper.js's offset docs . |
flip |
boolean |
yinyani |
Vumela i-Dropdown ukuba ijike xa kukho ukugqithelana kwindawo yereferensi. Ngolwazi oluthe vetshe jonga kuPopper.js's flip docs . |
umda |
umtya | isiqalelo |
'skrolaMzali' |
Umda wothintelo lokuphuphumayo kwimenyu eyehlayo. Yamkela amaxabiso e- 'viewport' , 'window' , 'scrollParent' , okanye i-HTMLElement ireferensi (iJavaScript kuphela). Ngolwazi oluthe vetshe bhekisa kuPopper.js's preventOverflow docs . |
isalathiso |
umtya | isiqalelo |
'guqula' |
Isalathiso sesiqalelo semenyu eyehlayo. Yamkela amaxabiso e- 'toggle' , 'parent' , okanye i-HTMLElement ireferensi. Ngolwazi oluthe vetshe bhekisa kuPopper.js's referenceObject docs . |
umboniso |
umtya |
'dynamic' |
Ngokungagqibekanga, sisebenzisa iPopper.js kwindawo eguqukayo. Khubaza oku nge static . |
popperConfig |
null | into |
null |
Ukutshintsha uqwalaselo olungagqibekanga lweBootstrap lwePopper.js, bona uqwalaselo lwePopper.js |
Qaphela xa boundary
imiselwe kulo naliphi na ixabiso ngaphandle 'scrollParent'
, isimbo position: static
sisetyenziswa .dropdown
kwisikhongozeli.
Iindlela
Indlela |
Inkcazo |
$().dropdown('toggle') |
Qwalasela imenyu eyehlayo ye-navbar enikiweyo okanye ukukhangela kwe-tabbed. |
$().dropdown('show') |
Ibonisa imenyu eyehlayo ye-navbar enikiweyo okanye ukukhangela kwe-tabbed. |
$().dropdown('hide') |
Ifihla imenyu eyehlayo ye-navbar enikiweyo okanye ukukhangela kwe-tabbed. |
$().dropdown('update') |
Ihlaziya indawo yokwehla kwento. |
$().dropdown('dispose') |
Itshabalalisa into eyehlayo. |
Iziganeko
Zonke iziganeko ezihlayo ziyagxothwa .dropdown-menu
kumzali kwaye relatedTarget
zinepropati, exabiso layo lisisiqalelo seankile eshukumayo. hide.bs.dropdown
kunye hidden.bs.dropdown
neziganeko clickEvent
zinepropati (kuphela xa uhlobo lwesiganeko sokuqala click
) equlathe iNjongo yeSigaba somnyadala wonqakrazo.
Isiganeko |
Inkcazo |
show.bs.dropdown |
Esi siganeko sivutha ngokukhawuleza xa indlela yokubonisa umboniso ibizwa. |
shown.bs.dropdown |
Esi siganeko sigxothwa xa ukwehla kwenziwe kwabonakala kumsebenzisi (uya kulinda iinguqu zeCSS, ukugqiba). |
hide.bs.dropdown |
Esi siganeko sigxothwa ngokukhawuleza xa indlela yokufihla umzekelo ibizwe. |
hidden.bs.dropdown |
Esi siganeko sigxothwa xa ukwehla kugqityiwe ukufihlwa kumsebenzisi (iya kulinda iinguqulelo zeCSS, ukuba zigqitywe). |