Zotsitsa
Sinthani zokulirapo kuti muwonetse mndandanda wamaulalo ndi zina zambiri ndi pulogalamu yowonjezera ya Bootstrap.
Madontho otsika amatha kusinthika, ndikuwunjikana pazowonetsa mndandanda wamaulalo ndi zina zambiri. Amapangidwa kuti azilumikizana ndi pulogalamu yowonjezera ya Bootstrap ya JavaScript. Amasinthidwa ndikudina, osati kungoyang'ana; ichi ndi chisankho chopanga mwadala.
Zotsitsa zimamangidwa palaibulale ya anthu ena, Popper.js , yomwe imapereka mawonekedwe osinthika komanso kuzindikira malo owonera. Onetsetsani kuti mwaphatikiza popper.min.js pamaso pa Bootstrap's JavaScript kapena gwiritsani ntchito bootstrap.bundle.min.js
/ bootstrap.bundle.js
yomwe ili ndi Popper.js. Popper.js sichigwiritsidwa ntchito poyika zotsikira mu navbars ngakhale kuti kuyimitsidwa kosunthika sikofunikira.
Ngati mukupanga JavaScript yathu kuchokera kugwero, pamafunikautil.js
.
Muyezo wa WAI ARIA umatanthawuza role="menu"
widget yeniyeni , koma iyi ndi mindandanda yazantchito yomwe imayambitsa zochita kapena ntchito. Mindandanda ya ARIA imatha kukhala ndi menyu, zinthu zamabokosi, zinthu za batani la wailesi, magulu a batani la wailesi, ndi ma menyu ang'onoang'ono.
Zotsitsa za Bootstrap, kumbali ina, zidapangidwa kuti zikhale zanthawi zonse komanso zogwiritsidwa ntchito pazosiyanasiyana komanso mawonekedwe. Mwachitsanzo, ndizotheka kupanga zotsitsa zomwe zimakhala ndi zowonjezera ndi zowongolera mawonekedwe, monga malo osakira kapena mafomu olowera. Pazifukwa izi, Bootstrap sayembekezera (kapena kungowonjezera) chilichonse role
mwazofunikira pamamenyu aria-
enieni a ARIA . Olemba akuyenera kuphatikizirapo izi mwapadera iwo eni.
Komabe, Bootstrap imawonjezera chithandizo chokhazikika pazolumikizana zambiri zamakiyibodi, monga kutha kusuntha pazinthu .dropdown-item
zilizonse pogwiritsa ntchito makiyi a cholozera ndikutseka menyu ndi ESCkiyi.
Manga chosinthira chotsitsa (batani lanu kapena ulalo) ndi menyu yotsikira mkati .dropdown
, kapena chinthu china chomwe chimalengeza position: relative;
. Zotsitsa zitha kuyambika kuchokera <a>
kapena <button>
zinthu kuti zigwirizane ndi zosowa zanu.
Chilichonse .btn
chikhoza kusinthidwa kukhala chotsitsa chotsitsa ndi zosintha zina. Umu ndi momwe mungawagwiritsire ntchito ndi <button>
zinthu zilizonse:
<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>
Ndipo ndi <a>
zinthu:
<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>
Gawo labwino kwambiri ndikuti mutha kuchita izi ndi batani lililonse, nanunso:
Momwemonso, pangani zotsitsa za batani zogawanika zokhala ndi chizindikiro chofanana ndi mabatani amodzi, koma ndikuwonjezera .dropdown-toggle-split
malo oyenera kuzungulira malo otsikira.
Timagwiritsa ntchito kalasi yowonjezerayi kuti tichepetse zopingasa padding
mbali zonse za chisamaliro ndi 25% ndikuchotsa margin-left
zomwe zimawonjezedwa pamakina otsika. Kusintha kowonjezerako kumapangitsa kuti chisamaliro chikhale chokhazikika mu batani logawanika ndikupereka malo ogunda moyenerera pafupi ndi batani lalikulu.
Mabatani otsikirapo amagwira ntchito ndi mabatani amitundu yonse, kuphatikiza mabatani otsikirapo ndi ogawanika.
Yambitsani mindandanda yotsikira pamwamba pa zinthu powonjezera .dropup
ku chinthu cha makolo.
Yambitsani mindandanda yotsikira kumanja kwa zinthu powonjezera .dropright
ku chinthu cha makolo.
Yambitsani mindandanda yotsikira kumanzere kwa zinthu powonjezera .dropleft
ku chinthu cha makolo.
Zakale zomwe zatsikira pansi zidayenera kukhala maulalo, koma sizili choncho ndi v4. Tsopano mutha kugwiritsa ntchito <button>
zinthu pazotsitsa zanu m'malo mwa <a>
s basi.
<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>
Mwachikhazikitso, menyu yotsitsa imayikidwa 100% kuchokera pamwamba ndi kumanzere kwa kholo lake. Onjezani .dropdown-menu-right
ku a .dropdown-menu
kulumikiza kumanja menyu yotsitsa.
Mungodziwiratu! Zotsitsa zimayikidwa chifukwa cha Popper.js (kupatula ngati zili mu 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>
Onjezani mutu kuti mulembe magawo a zochita mu menyu yotsikira.
<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>
Olekanitsa magulu azinthu zokhudzana ndi menyu ndi chogawa.
<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>
Ikani fomu mkati mwa menyu yotsitsa, kapena ipangitseni kukhala menyu yotsitsa, ndipo gwiritsani ntchito malire kapena ma padding kuti mupatse malo omwe mukufuna.
<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>
Onjezani .active
kuzinthu zomwe zili m'munsi kuti ziwoneke ngati zikugwira ntchito .
<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>
Onjezani .disabled
kuzinthu zomwe zili m'munsimu kuti zikhale ngati zolephereka .
<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>
Pogwiritsa ntchito mawonekedwe a data kapena JavaScript, pulogalamu yowonjezera yotsitsa imasintha zobisika (mindandanda yotsikira) posintha .show
kalasiyo pamndandanda wa makolo. Lingaliroli data-toggle="dropdown"
limadaliridwa potseka mindandanda yazakudya pamlingo wogwiritsa ntchito, ndiye ndibwino kuti muzigwiritsa ntchito nthawi zonse.
Pazida zomwe zimagwira, kutsegula kutsika kumawonjezera zopanda kanthu ( $.noop
) zogwirira mouseover
ntchito kwa ana omwe ali nawo <body>
. Kuthyolako kovomerezeka kumeneku ndikofunikira kuti mugwiritse ntchito movutikira muutumiki wa zochitika za iOS , zomwe zingalepheretse kugunda kulikonse kunja kwa dontho kuti zisayambitse khodi yomwe imatseka kutsitsa. Kutsitsa kukatsekedwa, zowongolera zopanda kanthu mouseover
izi zimachotsedwa.
Onjezani data-toggle="dropdown"
ku ulalo kapena batani kuti musinthe kutsitsa.
Imbani zotsitsa kudzera pa JavaScript:
data-toggle="dropdown"
zofunikabe
Mosasamala kanthu kuti mumayitanira kutsika kwanu kudzera pa JavaScript kapena m'malo mwake mugwiritse ntchito data-api, data-toggle="dropdown"
nthawi zonse imafunika kuti mukhalepo pazoyambitsa zotsitsa.
Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-
, monga mu data-offset=""
.
Dzina | Mtundu | Zosasintha | Kufotokozera |
---|---|---|---|
kuchepetsa | nambala | chingwe | ntchito | 0 | Kuchotsera kwa dontho lotsika poyerekeza ndi chandamale chake. Kuti mumve zambiri onani za Popper.js's offset docs . |
tembenuza | boolean | zoona | Lolani Dropdown itembenuke ngati pakhala palimodzi pagawo lolozera. Kuti mumve zambiri onani za Popper.js's flip docs . |
malire | chingwe | chinthu | 'scrollParent' | Malire oletsa kusefukira a menyu otsika. Imavomereza mfundo za 'viewport' , 'window' , 'scrollParent' , kapena HTMLElement reference (JavaScript yokha). Kuti mudziwe zambiri onani zolemba za preventOverflow za Popper.js . |
Zindikirani pamene boundary
akhazikitsidwa ku mtengo wina uliwonse kupatulapo 'scrollParent'
, kalembedwe kameneka position: static
kamagwiritsidwa ntchito pa .dropdown
chidebecho.
Njira | Kufotokozera |
---|---|
$().dropdown('toggle') |
Imatembenuza menyu yotsikira ya navbar yopatsidwa kapena kusakatula kwa tabu. |
$().dropdown('update') |
Imawonjezera pomwe pali kutsika kwa chinthu. |
$().dropdown('dispose') |
Imawononga kutsika kwa chinthu. |
Zochitika zonse zotsikira zimathamangitsidwa ku .dropdown-menu
's kholo element ndipo zimakhala ndi relatedTarget
katundu, zomwe mtengo wake ndi toggling nangula element.
Chochitika | Kufotokozera |
---|---|
show.bs.dropdown |
Chochitika ichi chimayaka nthawi yomweyo njira yachiwonetsero imatchedwa. |
shown.bs.dropdown |
Chochitikachi chimachotsedwa pamene kutsika kwawonekera kwa wogwiritsa ntchito (kudikira kusintha kwa CSS, kuti kumalize). |
hide.bs.dropdown |
Chochitikachi chimachotsedwa nthawi yomweyo njira yobisala itayitanidwa. |
hidden.bs.dropdown |
Chochitikachi chimachotsedwa pamene kutsitsa kwatha kubisidwa kwa wogwiritsa ntchito (kudikira kusintha kwa CSS, kuti kumalize). |