SourceDropdowns
Shandura kuvharika kwemamiriro ekutaridza rondedzero yezvinongedzo uye nezvimwe neBootstrap yekudonhedza plugin.
Overview
Madonhwe anogona kuchinjika, akafukidzirana pamusoro pekuratidzira rondedzero yezvinongedzo nezvimwe. Ivo vanoitwa kupindirana neiyo inosanganisirwa Bootstrap inodonha JavaScript plugin. Vanosandurwa nekudzvanya, kwete nekutenderera; ichi chisarudzo chekugadzira nemaune .
Kudonhedza kwakavakirwa pane yechitatu bato raibhurari, Popper.js , iyo inopa ine simba chinzvimbo uye kuona kwekutarisa. Iva nechokwadi chekuisa popper.min.js pamberi peBootstrap's JavaScript kana kushandisa bootstrap.bundle.min.js
/ bootstrap.bundle.js
iyo ine Popper.js. Popper.js haishandiswe kuisa zvinodonhedza mumabhara emvura asi sechinzvimbo chekuchinja chisingadiwi.
Kana iwe uri kuvaka yedu JavaScript kubva kunobva, zvinodautil.js
.
Accessibility
Iyo WAI ARIA chiyero inotsanangura iyo chaiyo role="menu"
widget , asi iyi yakanangana nemamenu ekushandisa anokonzeresa zviito kana mabasa. ARIA mamenu anogona chete kuve nemenu zvinhu, checkbox menyu zvinhu, redhiyo bhatani menyu zvinhu, redhiyo mabhatani mapoka, uye sub-mamenu.
Kudonhedza kweBootstrap, kune rumwe rutivi, kwakagadzirirwa kuve kwakajairwa uye kunoshanda kune akasiyana mamiriro uye makiko zvimiro. Semuyenzaniso, zvinokwanisika kugadzira madonhwe ane zvimwe zvekupinza uye zvidzoreso zvemafomu, senge minda yekutsvaga kana mafomu ekupinda. Nechikonzero ichi, Bootstrap haatarisiri (kana kuwedzera otomatiki) chero role
uye aria-
hunhu hunodiwa kune echokwadi ARIA menyu. Vanyori vanozofanira kusanganisira izvi zvakanyanya hunhu ivo pachavo.
Nekudaro, Bootstrap inowedzera yakavakirwa-mukati tsigiro yeakawanda akajairwa kiyibhodhi menyu kupindirana, sekugona kufamba nepakati .dropdown-item
pezvinhu zvega uchishandisa makiyi ecursor uye kuvhara menyu ESCnekiyi.
Mienzaniso
Putira iyo yekudonhedza toggle (bhatani rako kana chinongedzo) uye yekudonha menyu mukati .dropdown
, kana chimwe chinhu chinozivisa position: relative;
. Dropdowns inogona kukonzereswa kubva <a>
kana <button>
zvinhu kuti zvikwane zvaungade zvaunoda.
Chero imwe chete .btn
inogona kushandurwa kuita yekudonhedza dhizaini ine dzimwe markup shanduko. Heano maitiro aungaita kuti ashande nechero <button>
zvinhu:
Uye <a>
nezvinhu:
Chikamu chakanakisa ndechekuti iwe unogona kuita izvi nechero bhatani musiyano, zvakare:
Saizvozvo, gadzira kupatsanurwa bhatani kudonhedza pamwe neakafanana markup seyomwe bhatani kudonhedza, asi nekuwedzera kwenzvimbo .dropdown-toggle-split
yakakodzera yakatenderedza yekudonha caret.
Isu tinoshandisa iyi yekuwedzera kirasi kudzikisa yakachinjika padding
kune chero mativi ecaret ne25% uye kubvisa margin-left
iyo inowedzerwa kune yakajairwa mabhatani kudonhedza. Idzo shanduko dzekuwedzera dzinoita kuti caret igare pakati pebhatani rekutsemura uye inopa yakawedzera saizi yakarova nzvimbo padyo nebhatani guru.
Kukura
Mabhatani anodonhedza anoshanda nemabhatani eese saizi, kusanganisira default uye kupatsanura kudonhedza mabhatani.
Nhungamiro
Dropup
Tamba mamenu ekudonha pamusoro pezvinhu nekuwedzera .dropup
kune chinhu chemubereki.
Dropright
Tamba mamenu ekudonha kurudyi rwezvinhu nekuwedzera .dropright
kune chinhu chemubereki.
Dropleft
Tamba mamenu ekudonha kuruboshwe rwezvinhu nekuwedzera .dropleft
kune chinhu chemubereki.
Nhoroondo yekudonhedza menyu zvirimo zvaifanira kunge zviri zvinongedzo, asi hazvisisirizvo nev4. Iye zvino unogona kusarudza kushandisa <button>
zvinhu mukudonhedza kwako pane kungo <a>
s.
Iwe unogona zvakare kugadzira zvisingaite zvekudonhedza zvinhu ne .dropdown-item-text
. Inzwa wakasununguka kuwedzera chimiro netsika CSS kana zvinyorwa zvekushandisa.
Active
Wedzera .active
kuzvinhu zviri mukudonhedza kuti zvitayera sezviri kushanda .
Yakaremara
Wedzera .disabled
kuzvinhu zviri mukudonhedza kuti zvitaera sezvakaremara .
Nekumisikidza, menyu yekudonha inoiswa otomatiki 100% kubva kumusoro uye nekuruboshwe rwemubereki wayo. Wedzera .dropdown-menu-right
kune a .dropdown-menu
kune kurudyi gadzirisa menyu yekudonha.
Musoro! Madonhwe akaiswa panzvimbo yekutenda kune Popper.js (kunze kwekunge ari mubhara rekufamba).
Kugadzirisa kurongeka
Kana iwe uchida kushandisa inopindirana inopindura, dzima chinzvimbo chine simba nekuwedzera data-display="static"
hunhu uye shandisa inopindura mutsauko makirasi.
Kuti uenzanise menyu yekudonha neyakapuwa yakapihwa kana yakakura, wedzera .dropdown-menu{-sm|-md|-lg|-xl}-right
.
Kuti uenzanise kuruboshwe menyu yekudonha neyakapihwa yekutyora kana yakakura, wedzera .dropdown-menu-right
uye .dropdown-menu{-sm|-md|-lg|-xl}-left
.
Ziva kuti haufanire kuwedzera data-display="static"
hunhu kumabhatani ekudonhedza mumabhawa, sezvo Popper.js isingashandiswe mumabhawa.
Wedzera musoro kuti unyore zvikamu zvezviito mune chero kudonha menyu.
Vapesanisi
Mapoka akaparadzana ezvine hukama zvemenu ane divider.
Text
Isa chero mavara emahara mukati memenu yekudonha ine mavara uye shandisa spacing utilities . Ziva kuti iwe ungangoda mamwe masaizi masitaera kumanikidza menyu upamhi.
Isa fomu mukati memenu yekudonhedza, kana gadzira iyo yekudonha menyu, uye shandisa margin kana padding zvishandiso kuti uzvipe iyo isina kunaka nzvimbo yaunoda.
Dropdown options
Shandisa data-offset
kana data-reference
kushandura nzvimbo yekudonha.
Usage
Kuburikidza nehunhu hwedhata kana JavaScript, iyo yekudonha plugin inoshandura zvakavanzika zvemukati (mamenu ekudonha) nekuchinja .show
kirasi pane yevabereki rondedzero chinhu. Hunhu data-toggle="dropdown"
hunovimbwa nahwo pakuvhara mamenu ekudonha padanho rekushandisa, saka ipfungwa yakanaka kugara uchiishandisa.
Pazvishandiso zvinogonesa kubata, kuvhura kudonhedza kunowedzera isina chinhu ( $.noop
) mouseover
zvibatiso kune vekare vana <body>
vechinhu. Uku kubhejera kunobvumwa kwakashata kunodiwa kuti ushande zvakatenderedza muiOS' chiitiko delegation , iyo yaizodzivirira tepi chero kupi zvako kunze kwekudonha kubva kukonzeresa kodhi inovhara kudonha. Kamwe kudonhedza kwavharwa, aya ekuwedzera asina chinhu mouseover
anobatika anobviswa.
Via data hunhu
Wedzera data-toggle="dropdown"
kune chinongedzo kana bhatani kuti uchinje kudonhedza pasi.
Via JavaScript
Fonera zvinodonha kuburikidza neJavaScript:
data-toggle="dropdown"
zvichiri kudiwa
Kunyangwe iwe uchifonera kudonha kwako kuburikidza neJavaScript kana kuti panzvimbo pacho shandisa iyo data-api, data-toggle="dropdown"
inogara ichidikanwa kuti unge uripo pane inodonhedza inokonzeresa chinhu.
Options
Sarudzo dzinogona kupfuudzwa kuburikidza nedata hunhu kana JavaScript. Nezve data hunhu, wedzera iyo sarudzo zita ku data-
, semu data-offset=""
.
Zita |
Type |
Default |
Tsanangudzo |
offset |
nhamba | tambo | basa |
0 |
Offset yekudonha inoenderana nechinangwa chayo. Kuti uwane rumwe ruzivo tarisa kuPopper.js's offset docs . |
flip |
boolean |
chokwadi |
Bvumira Dropdown kuti itenderere kana pane kupindirana pane referensi chinhu. Kuti uwane rumwe ruzivo tarisa kuPopper.js's flip docs . |
muganhu |
tambo | element |
'scrollParent' |
Kufashukira kunomanikidza muganho weiyo yekudonha menyu. Inobvuma kukosha kwe 'viewport' , 'window' , 'scrollParent' , kana HTMLElement referensi (JavaScript chete). Kuti uwane rumwe ruzivo tarisa kune Popper.js's preventOverflow docs . |
reference |
tambo | element |
'shandura' |
Reference element yemenu yekudonha. Inobvuma kukosha kwe 'toggle' , 'parent' , kana HTMLElement referensi. Kuti uwane rumwe ruzivo tarisa kuPopper.js's referenceObject docs . |
kuratidza |
tambo |
'dynamic' |
Nekumisikidza, isu tinoshandisa Popper.js kune inoshanduka chinzvimbo. Dzima izvi ne static . |
Ziva kana boundary
yaiswa kune chero kukosha kunze 'scrollParent'
kwe, chimiro position: static
chinoshandiswa .dropdown
kumudziyo.
Nzira
Nzira |
Tsanangudzo |
$().dropdown('toggle') |
Shandura menyu yekudonhedza yakapihwa navbar kana tabbed navigation. |
$().dropdown('show') |
Inoratidza iyo yekudonha menyu yeakapihwa navbar kana tabbed navigation. |
$().dropdown('hide') |
Inoviga menyu yekudonhedza yeakapihwa navbar kana tabbed navigation. |
$().dropdown('update') |
Inovandudza nzvimbo yekudonha kwechimwe chinhu. |
$().dropdown('dispose') |
Inoparadza kudonha kwechimwe chinhu. |
Zviitiko
Zviitiko zvese zvekudonhedza zvinodzingirwa kune .dropdown-menu
's mubereki element uye zvine relatedTarget
pfuma, iyo kukosha kwayo ndiko kuchinjisa anchor element. hide.bs.dropdown
uye hidden.bs.dropdown
zviitiko zvine chivakwa clickEvent
(chete kana iyo yekutanga chiitiko mhando click
) ine Chiitiko Chinhu chechiitiko chekudzvanya.
Chiitiko |
Tsanangudzo |
show.bs.dropdown |
Ichi chiitiko chinopisa nekukasira kana iyo nzira yemuenzaniso inodanwa. |
shown.bs.dropdown |
Ichi chiitiko chinodzingwa kana kudonhedza kwaitwa kuti kuonekwe kumushandisi (ichamirira shanduko yeCSS, kuti ipedze). |
hide.bs.dropdown |
Chiitiko ichi chinodzingwa nekukasira kana nzira yekuhwanda yadaidzwa. |
hidden.bs.dropdown |
Chiitiko ichi chinodzingwa kana kudonhedza kwapera kuvanzwa kubva kumushandisi (ichamirira shanduko yeCSS, kuti ipedze). |