SourceOkwehliswayo
Guqula izimbondela zokuqukethwe ukuze ubonise izinhlu zezixhumanisi nokunye okwengeziwe nge-plugin eyehlayo ye-Bootstrap.
Uhlolojikelele
Okwehliswayo kuyaguquleka, imbondela yomongo yokubonisa izinhlu zezixhumanisi nokuningi. Enziwe asebenzisane ne-plugin ye-JavaScript eyehlayo ye-Bootstrap efakiwe. Aguqulwa ngokuchofoza, hhayi ngokuhambisa phezulu; lesi yisinqumo somklamo wamabomu .
Okwehliswayo kwakhelwe kulabhulali yezinkampani zangaphandle, i- Popper.js , ehlinzeka ngokuma okuguquguqukayo nokutholwa kwendawo yokubuka. Qiniseka ukuthi ufaka i- popper.min.js ngaphambi kweJavaScript ye-Bootstrap noma sebenzisa bootstrap.bundle.min.js
/ bootstrap.bundle.js
equkethe i-Popper.js. I-Popper.js ayisetshenziselwa ukubeka okwehlayo kuma-navbar nakuba ukuma okuguquguqukayo kungadingeki.
Uma wakha i-JavaScript yethu ngomthombo, idingautil.js
.
Ukufinyeleleka
Izinga le- WAI ARIArole="menu"
lichaza iwijethi yangempela , kodwa lokhu kuqondiswe kumamenyu afana nohlelo lokusebenza aqalisa izenzo noma imisebenzi. Amamenyu e -ARIA angaqukatha kuphela izinto zemenyu, izinto zemenyu yebhokisi lokuhlola, izinto zemenyu yezinkinobho zomsakazo, amaqembu ezinkinobho zomsakazo, namamenyu amancane.
Okwehliswayo kwe-Bootstrap, ngakolunye uhlangothi, kuklanyelwe ukuba kube yijenerikhi futhi kusebenze ezimeni ezahlukahlukene kanye nezakhiwo zokumaka. Isibonelo, kungenzeka ukudala okwehliswayo okuqukethe okokufaka okwengeziwe nezilawuli zefomu, njengezinkambu zokusesha noma amafomu okungena ngemvume. Ngalesi sizathu, i-Bootstrap ayilindele (noma yengeze ngokuzenzakalelayo) noma yiziphi role
izibaluli aria-
ezidingekayo kumamenyu e -ARIA eqiniso. Ababhali kuyodingeka bafake lezi zibaluli eziqondile ngokwabo.
Kodwa-ke, i-Bootstrap iyengeza usekelo olwakhelwe ngaphakathi lokusebenzisana kwemenyu yekhibhodi ejwayelekile, njengokukwazi ukuhamba phakathi .dropdown-item
kwezakhi ngazinye usebenzisa okhiye bekhesa nokuvala imenyu ESCngokhiye.
Izibonelo
Goqa inguquko yokudonsela phansi (inkinobho noma isixhumanisi sakho) kanye nemenyu yokudonsela phansi ngaphakathi .dropdown
, noma enye into ememezela position: relative;
. Okwehliswayo kungase kuqaliswe kusuka <a>
noma ama <button>
-elementi ukuze kulingane kangcono nezidingo zakho ezingaba khona.
Noma iyiphi ingoma eyodwa .btn
ingashintshwa ibe okokudonsela phansi ngezinye izinguquko zemakhaphu. Nansi indlela ongazisebenzisa ngayo noma yiziphi <button>
izici:
Futhi ngama- <a>
elementi:
Ingxenye engcono kakhulu ukuthi ungakwenza lokhu nganoma yikuphi okuhlukile kwenkinobho, futhi:
Ngokufanayo, dala okwehliswayo kwenkinobho yokuhlukanisa okunophawu olufanayo nolwehlayo lwenkinobho eyodwa, kodwa ngokungezwa kwesikhala .dropdown-toggle-split
esifanele endaweni yokunakekela okwehlayo.
Sisebenzisa lesi sigaba esengeziwe ukuze sinciphise okuvundlile padding
nhlangothi zombili ze-caret ngo-25% futhi sisuse margin-left
lokho okwengezwe ekwehliseni phansi kwezinkinobho ezivamile. Lezo zinguquko ezengeziwe zigcina i-caret igxile enkinobheni yokuhlukanisa futhi inikeza indawo yokushaya enosayizi ofanele eduze kwenkinobho eyinhloko.
Ukulinganisa
Okwehliswayo kwezinkinobho kusebenza ngezinkinobho zabo bonke osayizi, okuhlanganisa nezinkinobho ezizenzakalelayo nezihlukanisayo ezidonsela phansi.
Izikhombisi-ndlela
Ukwehliswa
Qalisa amamenyu okwehlayo ngenhla kwezici ngokwengeza .dropup
kusici esingumzali.
I-Droright
Qalisa amamenyu okwehlayo kwesokudla sezakhi ngokwengeza .dropright
kusici esingumzali.
I-Dropleft
Qalisa amamenyu okwehlayo kwesokunxele sezinto ngokwengeza .dropleft
kusici esingumzali.
Ngokomlando okuqukethwe kwemenyu eyehlayo bekufanele kube izixhumanisi, kodwa akusenjalo nge-v4. Manje ungakhetha ukusebenzisa <button>
izici kokwehliswayo kwakho esikhundleni sika- <a>
s nje.
Ungakwazi futhi ukudala izinto ezidonsela phansi ezingasebenzisani nge- .dropdown-item-text
. Zizwe ukhululekile ukwenza isitayela ngokuqhubekayo nge-CSS yangokwezifiso noma izinsiza zombhalo.
Iyasebenza
Engeza .active
ezintweni kokwehliswayo ukuze wenze isitayela njengezisebenzayo .
Ikhutshaziwe
Engeza .disabled
ezintweni kokwehliswayo ukuze wenze isitayela njengezikhutshaziwe .
Ngokuzenzakalelayo, imenyu yokudonsela phansi imiswa ngokuzenzakalelayo ngo-100% ukusuka phezulu nangakwesokunxele somzali wayo. Engeza .dropdown-menu-right
kokuthi a .dropdown-menu
ukuze uqondanise kwesokudla imenyu eyehlayo.
Amakhanda phezulu! Okwehliswayo kubekwe ngenxa ye-Popper.js (ngaphandle uma kuqukethwe ku-navbar).
Ukuqondanisa okusabelayo
Uma ufuna ukusebenzisa ukuqondanisa okusabelayo, khubaza ukuma okuguquguqukayo ngokungeza data-display="static"
isibaluli futhi usebenzise izigaba ezisabelayo zokuhlukahluka.
Ukuze uqondanise kwesokudla imenyu eyehlayo nendawo ehlukanisiwe enikeziwe noma enkulu, engeza .dropdown-menu{-sm|-md|-lg|-xl}-right
.
Ukuze uqondanise kwesokunxele imenyu eyehlayo nendawo ehlukanisiwe enikeziwe noma enkulu, engeza .dropdown-menu-right
futhi .dropdown-menu{-sm|-md|-lg|-xl}-left
.
Qaphela ukuthi awudingi ukwengeza data-display="static"
isibaluli kuzinkinobho ezidonsela phansi kuma-navbar, njengoba i-Popper.js ingasetshenziswa kuma-navbar.
Engeza unhlokweni kulebula izigaba zezenzo kunoma iyiphi imenyu eyehlayo.
Abahlukanisi
Hlukanisa amaqembu ezinto zemenyu ezihlobene ngesihlukanisi.
Umbhalo
Beka noma imuphi umbhalo we-freeform ngaphakathi kwemenyu eyehlayo onombhalo futhi usebenzise izinsiza zokuhlukanisa isikhala . Qaphela ukuthi cishe uzodinga izitayela zokulinganisa ezengeziwe ukuze ucindezele ububanzi bemenyu.
Faka ifomu kumenyu eyehlayo, noma ulenze libe yimenyu eyehlayo, bese usebenzisa imajini noma izinto zokunamathisela ukuze ulinikeze isikhala esingesihle osidingayo.
Izinketho zokwehlisa
Sebenzisa data-offset
noma data-reference
ushintshe indawo yokudonsela phansi.
Ukusetshenziswa
Ngezibaluli zedatha noma i-JavaScript, i-plugin eyehlayo iguqula okuqukethwe okufihliwe (amamenyu okwehliswayo) ngokuguqula .show
ikilasi entweni yohlu lwabazali. Isibaluli data-toggle="dropdown"
kuthenjelwe kuso ekuvaleni amamenyu okwehlayo ezingeni lesicelo, ngakho-ke kuwumqondo omuhle ukusisebenzisa njalo.
Kumadivayisi anikwe amandla ukuthinta, ukuvula okwehliswayo kwengeza izibambi ezingenalutho ( $.noop
) mouseover
ezinganeni eziseduze ze- <body>
elementi. Lokhu kugebenga okuvunyiwe ukuthi kubi kuyadingeka ukuze kulungiswe okuthile ekuthunyelweni komcimbi we-iOS , okungavimbela ukuthepha noma yikuphi ngaphandle kokwehliswayo ukuthi kungacuphi ikhodi evala okwehliswayo. Uma okwehliswayo sekuvaliwe, lezi mouseover
zibambi ezengeziwe ezingenalutho ziyasuswa.
Ngezibaluli zedatha
Engeza data-toggle="dropdown"
kusixhumanisi noma inkinobho ukuze uguqule okwehliswayo.
Nge-JavaScript
Shayela okwehliswayo nge-JavaScript:
data-toggle="dropdown"
kusadingeka
Kungakhathaliseki ukuthi ushayela okwehliswayo ucingo nge-JavaScript noma esikhundleni salokho sebenzisa i-data-api, data-toggle="dropdown"
kuyadingeka njalo ukuthi ube khona kusici sokuqala sokwehliswayo.
Izinketho
Izinketho zingadluliswa ngezibaluli zedatha noma i-JavaScript. Ukuze uthole izibaluli zedatha, faka igama lenketho kokuthi data-
, njengaku data-offset=""
.
Igama |
Uhlobo |
Okuzenzakalelayo |
Incazelo |
offset |
inombolo | umucu | umsebenzi |
0 |
I-offset yokwehliswayo ihlobene nethagethi yakhona. Ukuze uthole ulwazi olwengeziwe bheka ku-Popper.js's offset docs . |
flip |
boolean |
iqiniso |
Vumela Okwehlayo ukuthi kuphendulwe uma kwenzeka kugqagqana kusici sesithenjwa. Ukuze uthole ulwazi olwengeziwe bheka ku-Popper.js's flip docs . |
umngcele |
umucu | isici |
'scrollParent' |
Umkhawulo womkhawulo wokuchichima wemenyu eyehlayo. Yamukela amanani we- 'viewport' , 'window' , 'scrollParent' , noma ireferensi ye-HTMLElement (JavaScript kuphela). Ukuze uthole ulwazi olwengeziwe bheka ku-Popper.js's preventOverflow amadokhumenti . |
ireferensi |
umucu | isici |
'guqula' |
Isici esiyisethenjwa semenyu eyehlayo. Yamukela amanani okuthi 'toggle' , 'parent' , noma ireferensi Yesici se-HTML. Ukuze uthole ulwazi olwengeziwe bheka ku-Popper.js's referenceObject amadokhumenti . |
isibonisi |
umucu |
'dynamic' |
Ngokuzenzakalelayo, sisebenzisa i-Popper.js ekumiseni okuguquguqukayo. Khubaza lokhu nge- static . |
Qaphela boundary
ukuthi isethwe nini kunoma yiliphi inani ngaphandle kokuthi 'scrollParent'
, isitayela position: static
sisetshenziswa .dropdown
esitsheni.
Izindlela
Indlela |
Incazelo |
$().dropdown('toggle') |
Iguqula imenyu eyehlayo ye-navbar enikeziwe noma ukuzulazula okunethebhu. |
$().dropdown('show') |
Ibonisa imenyu eyehlayo ye-navbar enikeziwe noma ukuzulazula okunethebhu. |
$().dropdown('hide') |
Ifihla imenyu eyehlayo ye-navbar enikeziwe noma ukuzulazula okunethebhu. |
$().dropdown('update') |
Ibuyekeza indawo yokudonsela phansi kwe-elementi. |
$().dropdown('dispose') |
Icekela phansi i-elementi. |
Imicimbi
Yonke imicimbi eyehliswayo ixoshwa ku- .dropdown-menu
elementi engumzali futhi relatedTarget
inendawo, inani layo eliyi-elementi yehange eshintshayo. hide.bs.dropdown
futhi hidden.bs.dropdown
imicimbi clickEvent
inesici (kuphela uma uhlobo lomcimbi wangempela luyi click
) equkethe Into Yomcimbi yomcimbi wokuchofoza.
Umcimbi |
Incazelo |
show.bs.dropdown |
Lo mcimbi uvutha ngokushesha lapho indlela yesibonelo sombukiso ibizwa. |
shown.bs.dropdown |
Lo mcimbi uxoshwa lapho okwehliswayo kwenziwe kwabonakala kumsebenzisi (sizolinda izinguquko ze-CSS, ukuze ziqedele). |
hide.bs.dropdown |
Lo mcimbi uxoshwa ngokushesha lapho indlela yokufihla isibiziwe. |
hidden.bs.dropdown |
Lo mcimbi uxoshwa lapho okwehliswayo sekuqedile ukufihlwa kumsebenzisi (kuzolinda izinguquko ze-CSS, ukuze ziqedele). |