SourceUkwehla
Guqula umxholo wokwaleka ukuze ubonise uluhlu lwamakhonkco kunye nokunye kunye ne-Bootstrap yokuhla iplagi.
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
.
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.
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.
Amaqhosha okwehlayo asebenza ngamaqhosha abo bonke ubukhulu, kubandakanywa ukungagqibekanga kunye namaqhosha okulahla.
Qalisa imenyu eyehlayo ngentla kweziqalelo ngokongeza .dropup
kwinto engumzali.
Qalisa imenyu eyehlayo ekunene kwezinto ngokongeza .dropright
kwinto engumzali.
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.
Yongeza .active
kwizinto ezikuluhlu olusezantsi ukuze zizitayile njengezisebenzayo .
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).
Yongeza iheader ukulebhelisha amacandelo ezenzo kuyo nayiphi na imenyu eyehlayo.
Yahlula amaqela ezinto zemenyu ezinxulumeneyo kunye nesahluli.
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.
Sebenzisa data-offset
okanye data-reference
utshintshe indawo yokwehla.
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.
Yongeza data-toggle="dropdown"
kwikhonkco okanye iqhosha ukuguqula ukwehla.
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 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. 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 . |
Qaphela xa boundary
imiselwe kulo naliphi na ixabiso ngaphandle 'scrollParent'
, isimbo position: static
sisetyenziswa .dropdown
kwisikhongozeli.
Indlela |
Inkcazo |
$().dropdown('toggle') |
Qwalasela imenyu eyehlayo ye-navbar enikiweyo okanye ukukhangela kwe-tabbed. |
$().dropdown('update') |
Ihlaziya indawo yokwehla kwento. |
$().dropdown('dispose') |
Itshabalalisa into eyehlayo. |
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). |