Toggle contextual overlays walasa ka jɛgɛnsira lisi jira ani fɛn wɛrɛw ni Bootstrap jukɔrɔla yɔrɔ ye.
Kuma bɛɛ lajɛlen
Dropdowns bɛ se ka wuli ka bɔ ɲɔgɔn na, contextual overlays walasa ka jɛgɛnsira lisi jira ani fɛn wɛrɛw. U bɛ Kɛ ɲɔgɔndan ye ni Bootstrap 'kɔnɔ JavaScript 'kɔnɔ. U bɛ toggle ni klikɛli ye, a tɛ kɛ ni hovering ye; nin ye dilancogo latigɛlen ye ni laɲini ye .
Dropdowns bɛ jɔ mɔgɔ sabanan ka gafemarayɔrɔ dɔ kan, n’o ye Popper.js ye , min bɛ jɔyɔrɔfalen ni filɛlikɛyɔrɔw dɔnni di. Aw ye aw jija ka popper.min.js don a kɔnɔ ka kɔn Bootstrap ka JavaScript ɲɛ walima ka baara kɛ ni bootstrap.bundle.min.js/ bootstrap.bundle.jsye min kɔnɔ Popper.js bɛ sɔrɔ. Popper.js tɛ baara kɛ ka dropdownw bila navbars kɔnɔ hali ni dynamic positioning tɛ wajibiya.
WAI ARIA sariya bɛ role="menu"wideyo lakika dɔ ɲɛfɔ , nka o ye kɛrɛnkɛrɛnnenya la baarakɛminɛnw ye minnu bɛ kɛwalew walima baarakɛcogo dɔw daminɛ. ARIA menu kɔnɔ, menu kɔnɔfɛnw dɔrɔn de bɛ sɔrɔ, menu kɔnɔfɛnw, arajo butɔni menu kɔnɔfɛnw, arajo butɔni kuluw, ani menu fitininw.
Faan wɛrɛ fɛ, Bootstrap ka 'sènfɛ-sɛbɛnw Dabɔra walasa u ka Kɛ fɛn bɛɛ ye ani u bɛ Se ka Kɛ ko suguya caman na ani taamaʃyɛnw jɔcogo la. Misali la, a bɛ se ka kɛ ka fɛnw dilan minnu kɔnɔ, donnakow ni sɛbɛnw maracogo wɛrɛw bɛ sɔrɔ, i n’a fɔ ɲininikɛyɔrɔw walima donsɛbɛnw. O de kama, Bootstrap tɛ makɔnɔni kɛ (wa a tɛ a yɛrɛma fara a kan) roleani fɛn dɔw la aria-minnu wajibiyalen don ARIA menu lakikaw la. Sɛbɛnnikɛlaw yɛrɛ bɛna o jogo kɛrɛnkɛrɛnnenw don a kɔnɔ.
Nka, Bootstrap bɛ dɛmɛ Dòn a kɔnɔ ka Fàra klaviyeti menu (klaviyeti) menu (klaviyeti) 'kɔnɔ-ɲɔgɔnna fanba kan, i n'a fɔ se min bɛ Se ka Taa .dropdown-itemfɛn kelen-kelen bɛɛ fɛ ni cursor (kɛrɛnkɛrɛnnenya) klaviyetiw ye ani ka menu (dakun) Dabɔ ni ESCkey (klaviyeti) ye.
Misaliw
Aw bɛ jiginɛ in ka toggle (i ka butɔni walima i ka jɛgɛn) ani jiginɛ menu siri .dropdown, walima fɛn wɛrɛ min bɛ declare position: relative;. Dropdowns bɛ se ka daminɛ ka bɔ <a>walima <button>elements walasa ka bɛn i magow ma minnu bɛ se ka kɛ.
Butɔn kelen
Single o kelen .btnbɛ Se ka Yɛlɛma ka Kɛ 'yɔrɔ ye min bɛ 'yɔrɔ la ni 'yɔrɔ dɔw ye minnu bɛ 'yɔrɔ caman 'kɔnɔ. Aw bɛ se k’u bila baara la ni <button>fɛn fila la kelen ye cogo min na, o filɛ nin ye:
O cogo kelen na, aw bɛ butɔni tila-tilalenw dabɔ ni taamasiyɛn kelen ye ni butɔni kelen-kelenw ye, nka ni farali ye .dropdown-toggle-splitwalasa ka yɔrɔjan sɔrɔ ka ɲɛ karɛti lamini na.
An bɛ baara Kɛ ni nin kalasi wɛrɛ ye walasa ka karitɔn paddingfan fla bɛɛ la jɛgɛncogo Dɔgɔya ni 25% ye ani ka o margin-leftmin Fàrala butɔni 'kɔnɔ tuma bɛɛ kan, o Bɔ. O fɛn wɛrɛw bɛ kɛ ka karɛti bila cɛmancɛ la butɔni tilalen kɔnɔ ani ka butɔni belebele kɛrɛ fɛ, a bonya bɛnnen don.
Tariku la, menu kɔnɔfɛnw tun ka kan ka kɛ jɛgɛnw ye, nka o tɛ kɛ tugun v4 la. Sisan i bɛ Se ka baara Kɛ ni <button>fɛnw ye i yɛrɛ sago la i ka 'sènfɛ-sɛbɛnw kɔnɔ <a>s dɔrɔn nɔ na.
Aw bɛ se fana ka fɛnw dilan minnu tɛ ɲɔgɔn sɔrɔ ni .dropdown-item-text. Aw kana siga ka style kɛ ka taa a fɛ ni CSS walima sɛbɛnni nafamafɛnw ye minnu bɛ kɛ ka kɛɲɛ ni aw sago ye.
O cogo la, fɛn dɔ bɛ Dòn a yɛrɛ la 100% ka Bɔ sanfɛ ani a bangebaga kinin fɛ. A fara a kan .dropdown-menu-rightka .dropdown-menutaa kinin fɛ, i ka menu (yɔrɔ) labɛn.
Kungolow bɛ wuli! Dropdowns bɛ jɔyɔrɔ la Popper.js sababu la (n’a Bɔra n’u bɛ navbar dɔ kɔnɔ).
Alignment min bɛ jaabi di
N’i b’a fɛ ka baara kɛ ni jaabi-labɛnni ye, i ka dynamique positionnement bali ni data-display="static"attribut farali ye ani ka baara kɛ ni responsive variation classes ye.
Walasa ka menu (yɔrɔ) min bɛ jira, o bɛ bɛn kinin fɛ ni breakpoint dilen ye walima min ka bon, i ka fara .dropdown-menu{-sm|-md|-lg|-xl}-right.
Walasa ka menu (yɔrɔ) min bɛ bɔ kinin fɛ , o ni breakpoint dilen walima min ka bon ni o ye, i ka fara a kan .dropdown-menu-rightani .dropdown-menu{-sm|-md|-lg|-xl}-left.
A kɔlɔsi ko i man kan ka fɛn dɔ Fàra data-display="static"butɔni dɔw kan navbarw kɔnɔ, bawo Popper.js tɛ baara Kɛ navbarw kɔnɔ.
Meniw kɔnɔkow
Kungolodilanw
Aw bɛ kuncɛ dɔ fara a kan walasa ka walew yɔrɔw tɔgɔ sɛbɛn minnu bɛ sɔrɔ yɔrɔ o yɔrɔ la.
sɛbɛn hɔrɔnyalen o sɛbɛn hɔrɔnyalen bɛ yɔrɔ dɔ kɔnɔ ni sɛbɛnni ye ani ka baara kɛ ni yɔrɔjan nafamafɛnw ye . A kɔlɔsi ko a ka c’a la, i mago bɛna kɛ bonyacogo wɛrɛw la walasa ka menu bonya bali.
Misali sɛbɛn dɔw minnu bɛ free-flow kɔnɔ dropdown menu kɔnɔ.
Wa nin ye misali sɛbɛn ye min ka ca ni sɛbɛn ye.
Sɛbɛnw
I ka sɛbɛn dɔ bila fɛn dɔ kɔnɔ min bɛ jira, walima k’a kɛ fɛn dɔ ye min bɛ fɛnw jira, ani ka baara kɛ ni margin walima padding utilities ye walasa ka yɔrɔ jugu di a ma i mago bɛ min na.
Data attributes walima JavaScript fɛ, fɛn min bɛ fɛn dɔ jira, o bɛ kunnafoni dogolenw wuli (menuw) ni .showkalan sɛgɛsɛgɛli ye bangebagaw ka lisi yɔrɔ kan. O data-toggle="dropdown"fɛnɲɛnɛma in bɛ Da a kan walasa ka 'sènfɛjuru-minɛnw Dabɔ application (application) hakɛ dɔ la, o la a ka ɲi ka baara Kɛ n'a ye tuma bɛɛ.
$.noopMinɛn minnu bɛ se ka maga u la, ni i ye fɛn dɔ da wuli, o bɛ ( ) minɛlan lankolonw fara fɛn mouseoverin denw kan minnu bɛ u yɛrɛ la <body>. O admittedly ugly hack is necessary to work around a quirk in iOS’ event delegation , min n’o tɛ, o bɛna a bali ka tap dɔ kɛ yɔrɔ o yɔrɔ la ka bɔ dropdown kɔfɛ ka kode daminɛ min bɛ dropdown datugu. Ni jiginɛ datugulen don, o minɛn lankolon wɛrɛw mouseoverbɛ bɔ.
Ka tɛmɛn donanw ka fɛnw kan
A fara a kan data-toggle="dropdown"ka kɛ yɔrɔ dɔ ye walima ka butɔni dɔ fara a kan walasa ka fɛn dɔ wuli ka bɔ a nɔ na.
JavaScript fɛ
Aw bɛ fɛnw wele JavaScript fɛ:
data-toggle="dropdown"hali bi a wajibiyalen don
A mana Kɛ cogo o cogo n'i y'i ka 'dakun Weele JavaScript fɛ walima o nɔ na i bɛ baara Kɛ ni data-api ye, data-toggle="dropdown"a wajibiyalen don tuma bɛɛ ka Kɛ 'sènfɛ-sɛbɛnni-minɛn in 'kɔnɔ.
Sugandili minnu bɛ kɛ
Sugandili bɛ se ka tɛmɛ data attributes walima JavaScript fɛ. Donanw cogoyaw kama, aw bɛ sugandi tɔgɔ fara data-, i n’a fɔ a bɛ cogo min na data-offset="".
Tɔ̀gɔ
Ka sɛbɛen masin na
Fɔlɔ
Cogojirali
offset (fɔcogo ɲuman).
jate | juru | baarakunda
0 ye
Offset ka dropdown ka kɛɲɛ n’a laɲini ye.
Ni baarakɛcogo dɔ bɛ Kɛ ka 'offset (fɔcogo) Labɛn, a bɛ Weele ni fɛn dɔ ye min kɔnɔ offset (fɔcogo) data bɛ yen k'a Kɛ a ka dalilu fɔlɔ ye. Baarakɛcogo ka kan ka segin fɛn dɔ kan min jɔcogo ye kelen ye. Triggering element DOM node bɛ tɛmɛ i n’a fɔ argument filanan.
Walasa ka kunnafoni wɛrɛw sɔrɔ, aw ye Popper.js ka offset docs lajɛ .
kilape
boolean ye
sɛbɛ
A to Dropdown ka flip ni a kɛra ko dɔ bɛ ɲɔgɔn kan reference element kan. Walasa ka kunnafoni wɛrɛw sɔrɔ, aw ye Popper.js ka flip docs lajɛ .
dankan
juru | fɛn
'sɛbɛnni Bangebagaw'.
Overflow constraint dancɛ min bɛ sɔrɔ fɛnw jiracogo la. A bɛ Sɔn 'viewport', 'window', 'scrollParent', walima HTMLElement ɲɛfɔli dɔ nafaw ma (JavaScript dɔrɔn). Walasa ka kunnafoni wɛrɛw sɔrɔ, aw ye Popper.js ka preventOverflow docs lajɛ .
tàyɔrɔ
juru | fɛn
'toggle' ye.
Reference element min bɛ sɔrɔ menu kɔnɔ. A bɛ Sɔn 'toggle', 'parent', walima HTMLElement ka ɲɛfɔli nafaw ma. Walasa ka kunnafoni wɛrɛw sɔrɔ, aw ye Popper.js ka referenceObject docs lajɛ .
ka yira
gaari
'dinamiki'.
Ka da a kan, an bɛ baara Kɛ ni Popper.js ye walasa ka jɔyɔrɔfalen-falen Kɛ. Nin baara in bali ni static.
A kɔlɔsi ni boundarya sigilen bɛ nafa wɛrɛ la min tɛ 'scrollParent', cogoya position: staticbɛ kɛ .dropdownminɛn kɔnɔ.
Fɛɛrɛw
Kɛcogo
Cogojirali
$().dropdown('toggle')
A bɛ navbar walima navigation tabbed dilen dɔ ka menu dropdown wuli.
$().dropdown('show')
A bɛ navbar walima navigation tabbed dilen dɔ ka menu dropdown jira.
$().dropdown('hide')
A bɛ navbar walima navigation tabbed dilen dɔ ka menu dropdown dogo.
$().dropdown('update')
A bɛ fɛn dɔ ka 'yɔrɔ kura ye.
$().dropdown('dispose')
A bɛ element dɔ ka dropdown tiɲɛ.
Ko minnu kɛra
Fɛn minnu bɛ Dòn 'kɔnɔ olu bɛɛ bɛ Fɔ .dropdown-menu's parent element ('s parent element) la ani u bɛ ni relatedTargetnafolo ye, min nafa ye toggling anchor element ye. hide.bs.dropdownani hidden.bs.dropdownko kɛlenw bɛ ni clickEventnafolo ye (dɔrɔn ni ko kɛlen suguya fɔlɔ ye click) ye min kɔnɔ Ko kɛlen Fɛn dɔ bɛ yen min bɛ kɛ ka ɲɛsin klikɛli ko kɛlen ma.
Lajɛrɛ
Cogojirali
show.bs.dropdown
O ko in bɛ tasuma Bɔ o yɔrɔnin bɛɛ ni show instance fɛɛrɛ Weelera.
shown.bs.dropdown
O ko in bɛ Fɔ ni 'sènbɔli Kɛra baarakɛla fɛ (a bɛna CSS 'tɛmɛsiraw makɔnɔ, ka Dafa).
hide.bs.dropdown
O ko in bɛ Fɔ o yɔrɔnin bɛɛ ni hide instance fɛɛrɛ Weelera.
hidden.bs.dropdown
O ko in bɛ Fɔ ni 'sènfɛ-sɛbɛn in dogolen dòn baarakɛla fɛ (a bɛna CSS 'tɛmɛsiraw makɔnɔ, ka Dafa).