Source

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 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.jsyomwe 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 .

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 rolemwazofunikira 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-itemzilizonse pogwiritsa ntchito makiyi a cholozera ndikutseka menyu ndi ESCkiyi.

Zitsanzo

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.

Zotsitsa za batani limodzi

Chilichonse .btnchikhoza 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:

<!-- Example single danger button -->
<div class="btn-group">
  <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" 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>

Kutsitsa kwa batani logawanika

Momwemonso, pangani zotsitsa za batani zogawanika zokhala ndi chizindikiro chofanana ndi mabatani amodzi, koma ndikuwonjezera .dropdown-toggle-splitmalo oyenera kuzungulira malo otsikira.

Timagwiritsa ntchito kalasi yowonjezerayi kuti tichepetse zopingasa paddingmbali zonse za chisamaliro ndi 25% ndikuchotsa margin-leftzomwe zimawonjezedwa pamakina otsika. Kusintha kowonjezerako kumapangitsa kuti chisamaliro chikhale chokhazikika mu batani logawanika 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-haspopup="true" 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 otsikirapo ndi ogawanika.

<!-- 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-haspopup="true" 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-haspopup="true" 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-haspopup="true" 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-haspopup="true" aria-expanded="false">
    <span class="sr-only">Toggle Dropdown</span>
  </button>
  <div class="dropdown-menu">
    ...
  </div>
</div>

Kusintha kosiyanasiyana

Yambitsani mindandanda yotsikira pamwamba pa zinthu powonjezera .dropupku chinthu cha makolo.

<!-- Default dropup button -->
<div class="btn-group dropup">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" 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-haspopup="true" aria-expanded="false">
    <span class="sr-only">Toggle Dropdown</span>
  </button>
  <div class="dropdown-menu">
    <!-- Dropdown menu links -->
  </div>
</div>

Kusiyana kwa Dropright

Yambitsani mindandanda yotsikira kumanja kwa zinthu powonjezera .droprightku chinthu cha makolo.

<!-- Default dropright button -->
<div class="btn-group dropright">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" 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-haspopup="true" aria-expanded="false">
    <span class="sr-only">Toggle Dropright</span>
  </button>
  <div class="dropdown-menu">
    <!-- Dropdown menu links -->
  </div>
</div>

Kusiyanasiyana kwa Dropleft

Yambitsani mindandanda yotsikira kumanzere kwa zinthu powonjezera .dropleftku chinthu cha makolo.

<!-- Default dropleft button -->
<div class="btn-group dropleft">
  <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" 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" role="group">
    <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" 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>

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-rightku a .dropdown-menukulumikiza 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>

Zinthu zomwe zimagwira ntchito menyu

Onjezani .activekuzinthu 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>

Zinthu zolemala za menyu

Onjezani .disabledkuzinthu 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>

Kugwiritsa ntchito

Pogwiritsa ntchito mawonekedwe a data kapena JavaScript, pulogalamu yowonjezera yotsitsa imasintha zobisika (mindandanda yotsikira) posintha .showkalasiyo 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 mouseoverntchito 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 mouseoverizi zimachotsedwa.

Kudzera muzochita za data

Onjezani data-toggle="dropdown"ku ulalo kapena batani kuti musinthe kutsitsa.

<div class="dropdown">
  <button id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown trigger
  </button>
  <div class="dropdown-menu" aria-labelledby="dLabel">
    ...
  </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. 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 boundaryakhazikitsidwa ku mtengo wina uliwonse kupatulapo 'scrollParent', kalembedwe kameneka position: statickamagwiritsidwa ntchito pa .dropdownchidebecho.

Njira

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

Zochitika zonse zotsikira zimathamangitsidwa ku .dropdown-menu's kholo element ndipo zimakhala ndi relatedTargetkatundu, 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).
$('#myDropdown').on('show.bs.dropdown', function () {
  // do something…
})