Toggle contextual overlays walasa ka jɛgɛnsira lisi jira ani fɛn wɛrɛw ni Bootstrap dropdown plugin 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ɔko ni filɛlikɛyɔrɔw dɔnni fangama 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.
Bootstrap ka dropdowns kɔni, u dabɔra ka kɛ fɛn bɛɛ ye ani ka baara kɛ ni ko suguya caman ye ani markup structures. 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 kari paddingfàn fla bɛɛ ka horizontal (yɔrɔjan) Dɔgɔya ni 25% ye ani ka margin-leftthat's added for regular button dropdowns (butɔni bɔgɔlanw) Bɔ. O fɛn wɛrɛw bɛ kɛ ka karɛti bila cɛmancɛ la butɔni tilalen na ani ka butɔni belebele kɛrɛ fɛ min bonya bɛ bɛn a ma.
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ɔ).
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 bila menu 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ɛ bɔ hɔrɔnya la 'yɔrɔ la min bɛ 'yɔrɔ la.
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ɔ.
Donanw ka fɛnɲɛnɛmaw fɛ
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. 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('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).