Okwehliswayo
Guqula izimbondela zokuqukethwe ukuze ubonise izinhlu zezixhumanisi nokunye okwengeziwe nge-plugin eyehlayo ye-Bootstrap.
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 sokuklama ngamabomu.
Okwehliswayo kwakhelwe kulabhulali yezinkampani zangaphandle, i- Popper.js , ehlinzeka ngokuma okuguquguqukayo nokutholwa kwembobo yokubuka. Qiniseka ukuthi ufaka i- popper.min.js ngaphambi kwe-JavaScript 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
.
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 ukuthi 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.
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:
<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>
Futhi ngama- <a>
elementi:
<div class="dropdown show">
<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>
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.
Okwehliswayo kwezinkinobho kusebenza ngezinkinobho zabo bonke osayizi, okuhlanganisa nezinkinobho ezizenzakalelayo nezihlukanisayo ezidonsela phansi.
Qalisa amamenyu okwehlayo ngenhla kwezici ngokwengeza .dropup
engxenyeni engumzali.
Qalisa amamenyu okwehlayo kwesokudla sezakhi ngokwengeza .dropright
kusici esingumzali.
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.
<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>
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).
<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>
Engeza unhlokweni kulebula izigaba zezenzo kunoma iyiphi imenyu eyehlayo.
<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>
Hlukanisa amaqembu ezinto zemenyu ezihlobene ngesihlukanisi.
<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>
Faka ifomu kumenyu eyehlayo, noma ulenze libe yimenyu eyehlayo, futhi usebenzise imajini noma izinto zokunamathisela ukuze ulinikeze isikhala esingesihle osidingayo.
<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>
<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>
Engeza .active
ezintweni kokwehliswayo ukuze wenze isitayela njengezisebenzayo .
<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>
Engeza .disabled
ezintweni kokwehliswayo ukuze wenze isitayela njengezikhutshaziwe .
<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>
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.
Engeza data-toggle="dropdown"
kusixhumanisi noma inkinobho ukuze uguqule okwehliswayo.
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 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 . |
Qaphela boundary
ukuthi isethwe nini kunoma yiliphi inani ngaphandle kokuthi 'scrollParent'
, isitayela position: static
sisetshenziswa .dropdown
esitsheni.
Indlela | Incazelo |
---|---|
$().dropdown('toggle') |
Iguqula imenyu eyehlayo ye-navbar enikeziwe noma ukuzulazula okunethebhu. |
$().dropdown('update') |
Ibuyekeza indawo yokudonsela phansi kwe-elementi. |
$().dropdown('dispose') |
Icekela phansi i-elementi. |
Yonke imicimbi eyehliswayo ixoshwa ku- .dropdown-menu
elementi engumzali futhi relatedTarget
inendawo, inani layo eliyi-elementi yehange eshintshayo.
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 uyaxoshwa lapho okwehliswayo sekuqedile ukufihlwa kumsebenzisi (kuzolinda izinguquko ze-CSS, ukuze ziqedele). |