Mbelata
Gbanwee ihe mkpuchi gburugburu maka igosipụta ndepụta njikọ yana ihe ndị ọzọ na ngwa mgbakwunye Bootstrap.
Mbudata bụ mgbanwe mgbanwe, machie gburugburu maka igosipụta ndepụta njikọ yana ndị ọzọ. Ejiri ngwa mgbakwunye Bootstrap dropdown Javascript mekọrịta ha. A na-atụgharị ha site na ịpị, ọ bụghị site na ịnyagharị; nke a bụ mkpebi imewe nke a kpachapụrụ anya.
A na-ewu mkpọda n'ọbá akwụkwọ nke ndị ọzọ, Popper.js , nke na-enye ọnọdụ dị ike na nchọpụta nlele. Jide n'aka na ị gụnyere popper.min.js tupu Bootstrap's JavaScript ma ọ bụ jiri bootstrap.bundle.min.js
/ bootstrap.bundle.js
nke nwere Popper.js. A naghị eji Popper.js dobe dropdowns na navbars n'agbanyeghị na ọ dịghị mkpa n'ọkwa dị ike.
Ọ bụrụ na ị na-ewu Javascript anyị site na isi iyi, ọ chọrọutil.js
.
Ọkọlọtọ WAI ARIA na -akọwapụta role="menu"
wijetị n'ezie , mana nke a bụ kpọmkwem maka ngwa-dị ka ngwa nke na-akpalite omume ma ọ bụ ọrụ. Nchịkọta ARIA nwere ike ịnwe naanị ihe nchịkọta nhọrọ, ihe nchịkọta nhọrọ igbe igbe, ihe nchịkọta nhọrọ bọtịnụ redio, otu bọtịnụ redio, na obere menus.
N'aka nke ọzọ, emebere bootstrap's dropdowns ka ọ bụrụ ọnụ na ọdabara n'ọnọdụ dị iche iche yana nhazi akara. Dịka ọmụmaatụ, ọ ga-ekwe omume ịmepụta mkpọda nwere ntinye agbakwunyere yana njikwa ụdị, dị ka mpaghara ọchụchọ ma ọ bụ ụdị nbanye. N'ihi nke a, Bootstrap anaghị atụ anya (ma ọ bụ tinye ya ozugbo) nke ọ bụla role
na aria-
njirimara achọrọ maka ezigbo menus ARIA . Ndị ode akwụkwọ ga-etinyerịrị njirimara ndị a n'onwe ha.
Agbanyeghị, Bootstrap na-agbakwunye nkwado arụnyere n'ime ọtụtụ mmekọrịta menu nke ahụigodo, dị ka ike iji .dropdown-item
igodo cursor mechie menu site na ihe ESCdị iche iche.
Kechie ngbanwe nke dropdown (bọtịnụ gị ma ọ bụ njikọ gị) yana menu ndọpụta n'ime .dropdown
, ma ọ bụ ihe ọzọ na-ekwupụta position: relative;
. Enwere ike ịkpalite mbelata site na <a>
ma ọ bụ <button>
ihe iji kwado mkpa gị nke ọma.
Enwere .btn
ike ịtụgharị otu ọ bụla ka ọ bụrụ ntụgharị mkpọda nwere ụfọdụ mgbanwe akara. Nke a bụ otu ị ga-esi tinye ha ka ha jiri <button>
ihe abụọ ọ bụla rụọ ọrụ:
<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>
Na <a>
ihe ndị a:
<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>
Akụkụ kachasị mma bụ na ị nwere ike ime nke a site na iji ụdị bọtịnụ ọ bụla, kwa:
N'otu aka ahụ, mepụta mkpọda bọtịnụ nkewa nwere ihe fọrọ nke nta ka ọ bụrụ otu akara dị ka otu ndetu bọtịnụ, mana yana mgbakwunye .dropdown-toggle-split
maka oghere kwesịrị ekwesị n'akụkụ ebe nchekwa dropdown.
Anyị na-eji klaasị mgbakwunye a iji belata kehoraizin padding
n'akụkụ ọ bụla nke nlekọta ahụ site na 25% wee wepụ margin-left
nke ahụ agbakwunyere maka ndetu bọtịnụ oge niile. Mgbanwe ndị ahụ na-eme ka nlekọta ahụ dabere na bọtịnụ gbawara agbawa wee wepụta mpaghara kụrụ nke ọma karịa n'akụkụ bọtịnụ isi.
Mbelata bọtịnụ na-arụ ọrụ na bọtịnụ nha niile, gụnyere ndabara na bọtịnụ mwụda gbawara agbawa.
Kpalite menu ndọda n'elu ihe site na ịgbakwunye .dropup
na mmewere nne na nna.
Kpalite menu ndọda n'aka nri nke ihe ndị ahụ site na ịgbakwunye .dropright
na mmewere nne na nna.
Kpalite menu ndọda n'aka ekpe nke ihe ndị ahụ site na ịgbakwunye .dropleft
na mmewere nne na nna.
Ọdịnaya menu ndetu nke akụkọ ihe mere eme ga-abụrịrị njikọ, mana nke ahụ abụghịzi ikpe na v4. Ugbu a ị nwere ike iji <button>
ihe dị na dropdowns gị na nhọrọ nhọrọ kama naanị <a>
s.
<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>
Site na ndabara, a na-edobe menu ndetu ozugbo 100% site na elu yana n'akụkụ aka ekpe nke nne na nna ya. Tinye .dropdown-menu-right
na a .dropdown-menu
n'aka nri kwado menu ndọpụta.
Welie isi elu! A na-edobe ihe ndọghachi azụ n'ihi Popper.js (belụsọ mgbe ọ dị na 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>
Tinye nkụnye eji isi mee ka aha ngalaba omume na nchịkọta nhọrọ ọ bụla.
<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>
Kewapụ iche nke ihe nchịkọta nhọrọ nwere nkesa.
<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>
Tinye mpempe akwụkwọ n'ime menu ndọpụta, ma ọ bụ mee ya ka ọ bụrụ menu ndọpụta, ma jiri oke ma ọ bụ ihe nkpuchi iji nye ya ohere na-adịghị mma ịchọrọ.
<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>
Tinye .active
na ihe ndị dị na ndọpụta iji mee ka ha dị ka ndị na-arụ ọrụ .
<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>
Tinye .disabled
na ihe ndị dị na ndọpụta iji mee ka ha nwee nkwarụ .
<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>
Site na njirimara data ma ọ bụ Javascript, ngwa mgbakwunye na-atụgharị ọdịnaya zoro ezo (nchịkọta mkpọda) site na ịtụgharị .show
klaasị na ihe ndepụta nne na nna. A data-toggle="dropdown"
na-adabere na njirimara a maka imechi menus dropdown na ọkwa ngwa, yabụ ọ dị mma iji ya mgbe niile.
Na ngwaọrụ enyere aka, imepe mkpọda na-agbakwunye ndị na-ahụ maka ihe efu ( $.noop
) mouseover
na ụmụaka nke <body>
mmemme ahụ. Nke a na-ekweta jọrọ njọ mbanye anataghị ikike dị mkpa na-arụ ọrụ gburugburu a quirk na iOS' event nnọchiteanya , nke ga-ma ọ bụghị gbochie a mgbata n'ebe ọ bụla n'èzí dropdown si ịkpalite koodu na-emechi dropdown. Ozugbo emechiri ndọpụta ahụ, a mouseover
ga-ewepụ ndị njikwa efu ndị ọzọ.
Tinye data-toggle="dropdown"
na njikọ ma ọ bụ bọtịnụ ka ịgbanwee mkpọda.
Kpọọ dropdowns site na Javascript:
data-toggle="dropdown"
ka achọrọ
N'agbanyeghị ma ị na-akpọ dropdown gị site na Javascript ma ọ bụ kama iji data-api, data-toggle="dropdown"
a na-achọrọ mgbe niile ịnọ na ihe mkpalite dropdown.
Enwere ike ịfefe nhọrọ site na njirimara data ma ọ bụ Javascript. Maka njirimara data, tinye aha nhọrọ na data-
, dị ka ọ dị na data-offset=""
.
Aha | Ụdị | Ọdabara | Nkọwa |
---|---|---|---|
nkwụsị | nọmba | eriri | ọrụ | 0 | Nkwụsị nke ndapụta n'akụkụ ebumnuche ya. Maka ozi ndị ọzọ rụtụ aka na Docs Offset Popper.js . |
tụgharịa | boolean | eziokwu | Kwe ka ọ daa ka ọ tụgharịa ma ọ bụrụ na ọ dakọtara na mmewere ntụaka. Maka ozi ndị ọzọ rụtụ aka na docs tụgharịa nke Popper.js . |
oke | eriri | mmewere | 'mpịakọta nne na nna' | Oke oke mmachi nke menu ndọpụta. Nabata ụkpụrụ nke 'viewport' , 'window' , 'scrollParent' , ma ọ bụ HTMLElement ntụaka (naanị JavaScript). Maka ozi ndị ọzọ rụtụ aka na Docs preventoverflow nke Popper.js . |
Rịba ama mgbe boundary
atọrọ na uru ọ bụla na-abụghị 'scrollParent'
, a na position: static
-etinye ụdị ahụ na .dropdown
akpa ahụ.
Usoro | Nkọwa |
---|---|
$().dropdown('toggle') |
Na-atụgharị menu mwụda nke navbar enyere ma ọ bụ igodo taabụ. |
$().dropdown('update') |
Na-emelite ọnọdụ nke dropdown element. |
$().dropdown('dispose') |
Na-emebi mwepu nke mmewere. |
A na-achụpụ mmemme ndakpọ niile .dropdown-menu
na mmewere nne na nna ma nwee relatedTarget
akụrụngwa, nke uru ya bụ mmewere arịlịka na-atụgharị.
Ihe omume | Nkọwa |
---|---|
show.bs.dropdown |
Ihe omume a na-agba ọkụ ozugbo a na-akpọ usoro ihe ngosi. |
shown.bs.dropdown |
A na-agbanyụ mmemme a mgbe onye ọrụ mere ka mwepu ahụ hụ ya (ga-echere mgbanwe CSS, ka ọ mechaa). |
hide.bs.dropdown |
A na-agbapụ mmemme a ozugbo a kpọrọ usoro ihe nleba anya. |
hidden.bs.dropdown |
A na-agbapụ mmemme a mgbe ezoro ezoro ya n'aka onye ọrụ dropdown (ga-echere mgbanwe CSS, iji wuchaa). |