Zotsitsa
Sinthani zokulirapo kuti muwonetse mndandanda wamaulalo ndi zina zambiri ndi pulogalamu yowonjezera ya Bootstrap.
Mwachidule
Madontho otsika amatha kusinthika, ndikuwunjikana pazowonetsa mndandanda wamaulalo ndi zina zambiri. Amapangidwa kuti azilumikizana ndi pulogalamu yowonjezera ya JavaScript yophatikizidwa ya Bootstrap. Amasinthidwa ndikudina, osati kungoyang'ana; ichi ndi chisankho chopanga mwadala .
Zotsitsa zimamangidwa palaibulale ya anthu ena, Popper , yomwe imapereka mawonekedwe osinthika komanso kuzindikira malo owonera. Onetsetsani kuti mukuphatikiza popper.min.js pamaso pa Bootstrap's JavaScript kapena gwiritsani ntchito bootstrap.bundle.min.js
/ bootstrap.bundle.js
yomwe ili ndi Popper. Popper sagwiritsidwa ntchito kuyika zotsikira mu navbars ngakhale kuti kuyimitsidwa kosunthika sikofunikira.
Ngati mukupanga JavaScript yathu kuchokera kugwero, pamafunikautil.js
.
Kufikika
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.
Zitsanzo
Manga chosinthira chotsitsa (batani kapena ulalo wanu) 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.
Batani limodzi
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" data-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<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>
</div>
Ndipo ndi <a>
zinthu:
<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-expanded="false">
Dropdown link
</a>
<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>
</div>
Gawo labwino kwambiri ndikuti mutha kuchita izi ndi batani lililonse, nanunso:
<!-- Example single danger button -->
<div class="btn-group">
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Action
</button>
<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>
</div>
Kugawa batani
Momwemonso, pangani zotsitsa za batani logawanika 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 logawika ndikupereka malo ogunda moyenerera pafupi ndi batani lalikulu.
<!-- Example split danger button -->
<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
<button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<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>
</div>
Kukula
Mabatani otsikirapo amagwira ntchito ndi mabatani amitundu yonse, kuphatikiza mabatani osasintha komanso otsika.
<!-- Large button groups (default and split) -->
<div class="btn-group">
<button class="btn btn-secondary btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
Large button
</button>
<div class="dropdown-menu">
...
</div>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-lg" type="button">
Large split button
</button>
<button type="button" class="btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
...
</div>
</div>
<!-- Small button groups (default and split) -->
<div class="btn-group">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
Small button
</button>
<div class="dropdown-menu">
...
</div>
</div>
<div class="btn-group">
<button class="btn btn-secondary btn-sm" type="button">
Small split button
</button>
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
...
</div>
</div>
Mayendedwe
Kusiya
Yambitsani mindandanda yotsikira pamwamba pa zinthu powonjezera .dropup
ku chinthu cha makolo.
<!-- Default dropup button -->
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Dropup
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
</div>
</div>
<!-- Split dropup button -->
<div class="btn-group dropup">
<button type="button" class="btn btn-secondary">
Split dropup
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
</div>
</div>
Dropright
Yambitsani mindandanda yotsikira kumanja kwa zinthu powonjezera .dropright
ku chinthu cha makolo.
<!-- Default dropright button -->
<div class="btn-group dropright">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Dropright
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
</div>
</div>
<!-- Split dropright button -->
<div class="btn-group dropright">
<button type="button" class="btn btn-secondary">
Split dropright
</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropright</span>
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
</div>
</div>
Dropleft
Yambitsani mindandanda yotsikira kumanzere kwa zinthu powonjezera .dropleft
ku chinthu cha makolo.
<!-- Default dropleft button -->
<div class="btn-group dropleft">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Dropleft
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
</div>
</div>
<!-- Split dropleft button -->
<div class="btn-group">
<div class="btn-group dropleft">
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false">
<span class="sr-only">Toggle Dropleft</span>
</button>
<div class="dropdown-menu">
<!-- Dropdown menu links -->
</div>
</div>
<button type="button" class="btn btn-secondary">
Split dropleft
</button>
</div>
Zinthu za menyu
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" data-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu">
<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>
Mutha kupanganso zinthu zosagwiritsa ntchito potsitsa ndi .dropdown-item-text
. Khalani omasuka kuti muwonjezere mawonekedwe ndi CSS kapena zolemba.
<div class="dropdown-menu">
<span class="dropdown-item-text">Dropdown item text</span>
<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>
Yogwira
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>
Wolumala
Onjezani .disabled
kuzinthu zomwe zili m'munsi kuti muzisanjire ngati zolephereka .
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Regular link</a>
<a class="dropdown-item disabled">Disabled link</a>
<a class="dropdown-item" href="#">Another link</a>
</div>
Kusintha kwa menyu
Mwachikhazikitso, menyu yotsitsa imayikidwa 100% kuchokera pamwamba ndi kumanzere kwa kholo lake. Onjezani .dropdown-menu-right
ku a .dropdown-menu
kulumikiza kumanja menyu yotsitsa.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" 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>
Mayalikidwe omvera
Ngati mukufuna kugwiritsa ntchito kuyanjanitsa komvera, zimitsani kuyika kwamphamvu powonjezera mawonekedwe data-display="static"
ndikugwiritsa ntchito makalasi omvera.
Kuti muyanjanitse menyu yotsikirayo ndi malo omwe mwapatsidwa kapena okulirapo, onjezani .dropdown-menu{-sm|-md|-lg|-xl}-right
.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" data-display="static" aria-expanded="false">
Left-aligned but right aligned when large screen
</button>
<div class="dropdown-menu dropdown-menu-lg-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>
Kuti muyanjanitse kumanzere menyu yotsitsa ndi malo omwe mwapatsidwa kapena okulirapo, onjezani .dropdown-menu-right
ndi .dropdown-menu{-sm|-md|-lg|-xl}-left
.
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" data-display="static" aria-expanded="false">
Right-aligned but left aligned when large screen
</button>
<div class="dropdown-menu dropdown-menu-right dropdown-menu-lg-left">
<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>
Zindikirani kuti simukuyenera kuwonjezera mawonekedwe data-display="static"
pamabatani otsitsa mu navbars, popeza Popper sagwiritsidwa ntchito mu navbars.
Zomwe zili pamenyu
Mitu
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>
Ogawanitsa
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>
Mawu
Ikani mawu aliwonse aulere mkati mwa menyu otsika omwe ali ndi mawu ndikugwiritsa ntchito masitayilo . Dziwani kuti mudzafunika masitayelo owonjezera kuti muchepetse kukula kwa menyu.
<div class="dropdown-menu p-4 text-muted" style="max-width: 200px;">
<p>
Some example text that's free-flowing within the dropdown menu.
</p>
<p class="mb-0">
And this is more example text.
</p>
</div>
Mafomu
Ikani fomu mkati mwa menyu yotsitsa, kapena ipangitseni kukhala menyu yotsitsa, ndipo gwiritsani ntchito maginito 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-group">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck">
<label class="form-check-label" for="dropdownCheck">
Remember me
</label>
</div>
</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-group">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="dropdownCheck2">
<label class="form-check-label" for="dropdownCheck2">
Remember me
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Sign in</button>
</form>
Zosankha zotsitsa
Gwiritsani ntchito data-offset
kapena data-reference
kusintha malo otsitsa.
<div class="d-flex">
<div class="dropdown mr-1">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-expanded="false" data-offset="10,20">
Offset
</button>
<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>
</div>
<div class="btn-group">
<button type="button" class="btn btn-secondary">Reference</button>
<button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-expanded="false" data-reference="parent">
<span class="sr-only">Toggle Dropdown</span>
</button>
<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>
</div>
</div>
Kugwiritsa ntchito
Pogwiritsa ntchito mawonekedwe a data kapena JavaScript, pulogalamu yowonjezera yotsitsa imasintha zobisika (mindandanda yotsitsa) posintha .show
kalasi pa kholo .dropdown-menu
. Lingaliroli data-toggle="dropdown"
limadaliridwa potseka mindandanda yazakudya pamlingo wogwiritsa ntchito, ndiye ndibwino kuti muzigwiritsa ntchito nthawi zonse.
$.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.
Kudzera muzochita za data
Onjezani data-toggle="dropdown"
ku ulalo kapena batani kuti musinthe kutsitsa.
<div class="dropdown">
<button type="button" data-toggle="dropdown" aria-expanded="false">
Dropdown trigger
</button>
<div class="dropdown-menu">
...
</div>
</div>
Kudzera pa JavaScript
Imbani zotsitsa kudzera pa JavaScript:
$('.dropdown-toggle').dropdown()
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
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. Ntchito ikagwiritsidwa ntchito kuti izindikire kuchotsera, imatchedwa ndi chinthu chomwe chili ndi data ya offset ngati mkangano wake woyamba. Ntchitoyi iyenera kubweza chinthu chofanana. Choyambitsa chinthu cha DOM node chimadutsa ngati mkangano wachiwiri. Kuti mumve zambiri onani za Popper's offset docs . |
tembenuza | boolean | zoona | Lolani Dropdown itembenuke ngati pakhala palimodzi pagawo lolozera. Kuti mudziwe zambiri onani zolemba za Popper . |
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 za Popper's preventOverflow docs . |
umboni | chingwe | chinthu | 'kusintha' | Cholozera cha menyu otsika. Imavomereza mfundo za 'toggle' , 'parent' , kapena HTMLElement reference. Kuti mudziwe zambiri onani zolemba za Popper's referenceObject docs . |
chiwonetsero | chingwe | 'dynamic' | Mwachikhazikitso, timagwiritsa ntchito Popper poyimitsa ma dynamic positioning. Letsani izi ndi static . |
popperConfig | null | chinthu | null | Kuti musinthe kasinthidwe ka Popper ka Bootstrap, onani kasinthidwe ka Popper |
Zindikirani pamene boundary
ayikidwa pamtengo wina uliwonse kupatulapo 'scrollParent'
, kalembedwe kameneka position: static
kamagwiritsidwa ntchito pa .dropdown
chidebecho.
Njira
Njira | Kufotokozera |
---|---|
$().dropdown('toggle') |
Imatembenuza menyu yotsitsa ya navbar yopatsidwa kapena kusakatula kwa tabu. |
$().dropdown('show') |
Imawonetsa menyu otsikira a navbar yopatsidwa kapena navigation ya tabbed. |
$().dropdown('hide') |
Imabisa menyu yotsikira ya navbar yoperekedwa kapena kusakatula kwa tabu. |
$().dropdown('update') |
Imawonjezera pomwe pali kutsika kwa chinthu. |
$().dropdown('dispose') |
Imawononga kutsika kwa chinthu. |
Zochitika
Zochitika zonse zotsikira zimathamangitsidwa ku .dropdown-menu
's kholo element ndipo zimakhala ndi relatedTarget
katundu, zomwe mtengo wake ndi toggling nangula element. hide.bs.dropdown
ndipo hidden.bs.dropdown
zochitika zimakhala ndi clickEvent
katundu (pokhapo pamene mtundu wa chochitika choyambirira uli click
) chomwe chili ndi Chochitika Chochitika cha chochitikacho.
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 dontho latha kubisidwa kwa wogwiritsa ntchito (kudikira kusintha kwa CSS, kuti kumalize). |
$('#myDropdown').on('show.bs.dropdown', function () {
// do something...
})