Droch-dhìol
Tog ath-chòmhdach co-theacsail gus liostaichean de cheanglaichean agus barrachd a thaisbeanadh leis a’ plugan tuiteam-sìos Bootstrap.
Ro-shealladh
Tha dropdowns nan ath-chòmhdach co-theacsail toggle airson liostaichean de cheanglaichean agus barrachd a thaisbeanadh. Tha iad air an dèanamh eadar-ghnìomhach leis a’ plugan Bootstrap tuiteam-sìos JavaScript. Tha iad air an togail le cliogadh, chan ann le hovering; is e co-dhùnadh dealbhaidh a tha seo a dh’aona ghnothach .
Tha dropdowns air an togail air leabharlann treas pàrtaidh, Popper , a bheir seachad suidheachadh fiùghantach agus lorg sealladh. Dèan cinnteach gun cuir thu a-steach popper.min.js ro JavaScript Bootstrap no cleachd bootstrap.bundle.min.js
/ bootstrap.bundle.js
anns a bheil Popper. Cha bhith Popper air a chleachdadh airson dropdowns a shuidheachadh ann am bàraichean seòlaidh ged nach eil feum air suidheachadh fiùghantach.
Ma tha thu a’ togail ar JavaScript bhon tùs, feumaidhutil.js
e .
Ruigsinneachd
Tha inbhe WAI ARIA a’ mìneachadh fìor role="menu"
widget , ach tha seo sònraichte do chlàran-bìdh coltach ri tagradh a bhrosnaicheas gnìomhan no gnìomhan. Chan fhaod a bhith ann an clàir-bìdh ARIA ach nithean clàr, nithean clàr bogsa-seic, nithean clàr putan rèidio, buidhnean putan rèidio, agus fo-chlàran.
Air an làimh eile, tha dropdowns Bootstrap air an dealbhadh gus a bhith coitcheann agus iomchaidh airson grunn shuidheachaidhean agus structaran comharrachaidh. Mar eisimpleir, tha e comasach dropdowns a chruthachadh anns a bheil cuir a-steach a bharrachd agus smachdan foirm, leithid raointean sgrùdaidh no foirmean logadh a-steach. Air an adhbhar seo, chan eil Bootstrap a’ dùileachadh (no a’ cur ris gu fèin-ghluasadach) gin de na role
agus na aria-
buadhan a tha riatanach airson fìor chlàran ARIA . Feumaidh ùghdaran na buadhan nas sònraichte sin a ghabhail a-steach iad fhèin.
Ach, bidh Bootstrap a’ cur taic a-staigh airson a’ mhòr-chuid de eadar-obrachaidhean clàr meur-chlàr àbhaisteach, leithid an comas gluasad tro .dropdown-item
eileamaidean fa leth a’ cleachdadh iuchraichean a’ chursair agus an clàr a dhùnadh leis an ESCiuchair.
Eisimpleirean
Còmhdaich tog an tuiteam-sìos (am putan no an ceangal agad) agus an clàr a-nuas taobh a-staigh .dropdown
, no eileamaid eile a dhearbhas position: relative;
. Faodar dropdowns a bhrosnachadh bho <a>
no <button>
eileamaidean a fhreagras air na feumalachdan a dh’ fhaodadh a bhith agad.
Putan singilte
Faodar singilte sam bith .btn
a thionndadh gu bhith na tog sìos le beagan atharrachaidhean comharrachaidh. Seo mar as urrainn dhut an cur gu obair le gach <button>
eileamaid:
<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>
Agus le <a>
eileamaidean:
<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>
Is e am pàirt as fheàrr gun urrainn dhut seo a dhèanamh le tionndadh putan sam bith, cuideachd:
<!-- 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>
Putan sgoltadh
San aon dòigh, cruthaich dropdowns putan sgoltadh le cha mhòr an aon chomharra ri tuiteam sìos putan singilte, ach le bhith a’ cur a-steach .dropdown-toggle-split
farsaingeachd cheart timcheall air a ’chùram tuiteam-sìos.
Bidh sinn a’ cleachdadh a’ chlas a bharrachd seo gus a’ chòmhnard padding
air gach taobh den chùram a lughdachadh 25% agus thoir air falbh an margin-left
fheadhainn a tha air a chur ris airson putanan sìos gu cunbhalach. Bidh na h-atharrachaidhean a bharrachd sin a’ cumail a’ chùram sa mheadhan anns a’ phutan sgoltadh agus a’ toirt seachad àite bualaidh nas freagarraiche ri taobh a’ phrìomh phutan.
<!-- 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>
Meudachadh
Bidh dropdowns putan ag obair le putanan de gach meud, a’ toirt a-steach putanan bunaiteach agus sgoltadh sìos.
<!-- 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>
Stiùiridhean
Droch-dhiol
Cruthaich clàr-taice sìos os cionn eileamaidean le bhith a’ cur .dropup
ris an eileamaid phàrant.
<!-- 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
Dèan clàir-thaice air taobh deas nan eileamaidean le bhith a’ cur .dropright
ris an eileamaid phàrant.
<!-- 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>
Droch-dhiol
Dèan clàir-thaice air taobh clì nan eileamaidean le bhith a’ cur .dropleft
ris an eileamaid phàrant.
<!-- 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>
Feartan clàr-taice
Gu h-eachdraidheil dh'fheumadh susbaint clàr-taice a bhith mar cheanglaichean, ach chan eil sin fìor tuilleadh le v4. A-nis faodaidh tu <button>
eileamaidean a chleachdadh gu roghnach anns na dropdowns agad an àite dìreach <a>
s.
<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>
Faodaidh tu cuideachd nithean tuiteam-sìos neo-eadar-ghnìomhach a chruthachadh le .dropdown-item-text
. Faodaidh tu stoidhle a bharrachd a dhèanamh le CSS àbhaisteach no goireasan teacsa.
<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>
Gnìomhach
Cuir .active
ris na nithean anns a’ tuiteam-sìos gus an stoidhle mar ghnìomhach .
<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>
Ciorramach
Cuir .disabled
ri nithean anns a’ tuiteam-sìos gus an stoidhle mar ciorramach .
<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>
Co-thaobhadh clàr-taice
Gu gnàthach, tha clàr tuiteam-sìos air a shuidheachadh gu fèin-ghluasadach 100% bhon mhullach agus air taobh clì a phàrant. Cuir .dropdown-menu-right
ri a .dropdown-menu
gu deas co-thaobhadh ris a’ chlàr tuiteam-sìos.
<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>
Co-thaobhadh freagairteach
Ma tha thu airson co-thaobhadh freagairteach a chleachdadh, cuir à comas suidheachadh fiùghantach le bhith a’ cur a’ data-display="static"
fheart ris agus cleachd na clasaichean atharrachaidh freagairteach.
Gus an clàr tuiteam-sìos a cho-thaobhadh ceart leis a’ phuing-bhriseadh a chaidh a thoirt seachad no nas motha, cuir ris .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>
Gus an clàr-taice clì.dropdown-menu-right
a cho-thaobhadh leis a’ phuing-bhriseadh a chaidh a thoirt seachad no nas motha, cuir ris agus .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>
Thoir an aire nach fheum thu data-display="static"
feart a chuir ri putanan tuiteam-sìos ann an navbars, leis nach eil Popper air a chleachdadh ann am bàraichean seòlaidh.
Susbaint clàr-taice
Cinn-cinn
Cuir bann-cinn ris gus earrannan de ghnìomhan a chomharrachadh ann an clàr-taice sam bith.
<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>
Luchd-sgaraidh
Roinn buidhnean de stuthan clàr co-cheangailte le roinneadh.
<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>
Teacs
Cuir teacsa an-asgaidh sam bith taobh a-staigh clàr-taice le teacsa agus cleachd goireasan eadar-dhealaichte . Thoir an aire gur dòcha gum feum thu stoidhlichean meudachaidh a bharrachd gus leud a’ chlàr a chuingealachadh.
<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>
Foirmean
Cuir foirm taobh a-staigh clàr tuiteam-sìos, no dèan a-steach do chlàr tuiteam-sìos, agus cleachd goireasan iomaill no pleadhaig gus an àite àicheil a tha a dhìth ort a thoirt dha.
<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>
Roghainnean tuiteam-sìos
Cleachd data-offset
no data-reference
atharraich suidheachadh a’ chlàr tuiteam-sìos.
<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>
Cleachdadh
Tro bhuadhan dàta no JavaScript, bidh am plugan tuiteam-sìos a’ togail susbaint falaichte (clàran-taice sìos) le bhith a’ togail a’ .show
chlas air a’ phàrant .dropdown-menu
. Thathas data-toggle="dropdown"
an urra ris a’ fheart airson clàran-bìdh a dhùnadh sìos aig ìre tagraidh, agus mar sin is e deagh bheachd a th’ ann a chleachdadh an-còmhnaidh.
$.noop
)
mouseover
handlers to the immediate children of the
<body>
element. This admittedly ugly hack is necessary to work around a
quirk in iOS’ event delegation, which would otherwise prevent a tap anywhere outside of the dropdown from triggering the code that closes the dropdown. Once the dropdown is closed, these additional empty
mouseover
handlers are removed.
Via data attributes
Add data-toggle="dropdown"
to a link or button to toggle a dropdown.
<div class="dropdown">
<button type="button" data-toggle="dropdown" aria-expanded="false">
Dropdown trigger
</button>
<div class="dropdown-menu">
...
</div>
</div>
Via JavaScript
Call the dropdowns via JavaScript:
$('.dropdown-toggle').dropdown()
data-toggle="dropdown"
still required
Regardless of whether you call your dropdown via JavaScript or instead use the data-api, data-toggle="dropdown"
is always required to be present on the dropdown’s trigger element.
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-offset=""
.
Name | Type | Default | Description |
---|---|---|---|
offset | number | string | function | 0 | Offset of the dropdown relative to its target. When a function is used to determine the offset, it is called with an object containing the offset data as its first argument. The function must return an object with the same structure. The triggering element DOM node is passed as the second argument. For more information refer to Popper's offset docs. |
flip | boolean | true | Allow Dropdown to flip in case of an overlapping on the reference element. For more information refer to Popper's flip docs. |
boundary | string | element | 'scrollParent' | Overflow constraint boundary of the dropdown menu. Accepts the values of 'viewport' , 'window' , 'scrollParent' , or an HTMLElement reference (JavaScript only). For more information refer to Popper's preventOverflow docs. |
reference | string | element | 'toggle' | Reference element of the dropdown menu. Accepts the values of 'toggle' , 'parent' , or an HTMLElement reference. For more information refer to Popper's referenceObject docs. |
display | string | 'dynamic' | By default, we use Popper for dynamic positioning. Disable this with static . |
popperConfig | null | object | null | To change Bootstrap's default Popper config, see Popper's configuration |
Note when boundary
is set to any value other than 'scrollParent'
, the style position: static
is applied to the .dropdown
container.
Methods
Method | Description |
---|---|
$().dropdown('toggle') |
Toggles the dropdown menu of a given navbar or tabbed navigation. |
$().dropdown('show') |
Shows the dropdown menu of a given navbar or tabbed navigation. |
$().dropdown('hide') |
Hides the dropdown menu of a given navbar or tabbed navigation. |
$().dropdown('update') |
Updates the position of an element’s dropdown. |
$().dropdown('dispose') |
Destroys an element’s dropdown. |
Events
All dropdown events are fired at the .dropdown-menu
’s parent element and have a relatedTarget
property, whose value is the toggling anchor element. hide.bs.dropdown
and hidden.bs.dropdown
events have a clickEvent
property (only when the original event type is click
) that contains an Event Object for the click event.
Event | Description |
---|---|
show.bs.dropdown |
This event fires immediately when the show instance method is called. |
shown.bs.dropdown |
Thèid an tachartas seo a losgadh nuair a bhios an tuiteam-sìos ri fhaicinn don neach-cleachdaidh (feitheamh ri eadar-ghluasadan CSS, gus a chrìochnachadh). |
hide.bs.dropdown |
Thèid an tachartas seo a losgadh sa bhad nuair a thèid an dòigh seiche seiche a ghairm. |
hidden.bs.dropdown |
Thèid an tachartas seo a losgadh nuair a tha an tuiteam-sìos deiseil a bhith falaichte bhon neach-cleachdaidh (feitheamh ri eadar-ghluasadan CSS, gus a chrìochnachadh). |
$('#myDropdown').on('show.bs.dropdown', function () {
// do something...
})