Popovers a wɔde wɔn ho hyɛ mu
Nwoma ne nhwɛsoɔ a wode bɛka Bootstrap popovers, te sɛ deɛ wɔhunu wɔ iOS mu, wɔ element biara a ɛwɔ wo site no so.
Nsɛm a Wɔaka abom
Nneɛma a ɛsɛ sɛ wuhu bere a wode popover plugin no redi dwuma no:
- Popovers de wɔn ho to 3rd party nhomakorabea Popper so ma gyinabea. Ɛsɛ sɛ wode popper.min.js ka ho ansa na bootstrap.js anaa wode
bootstrap.bundle.min.js
/bootstrap.bundle.js
a Popper wom di dwuma na ama popovers ayɛ adwuma! - Popovers hwehwɛ tooltip plugin no sɛ ade a ɛde ne ho to so.
- Sɛ worekyekye yɛn JavaScript no afi fibea a, ɛhwehwɛ sɛ
util.js
. - Popovers yɛ opt-in esiane adwumayɛ nti, enti ɛsɛ sɛ w’ankasa wufi ase .
- Zero-tenten
title
necontent
gyinapɛn ahorow renkyerɛ popover da. - Kyerɛkyerɛ
container: 'body'
sɛnea wobɛkwati nkyerɛase ho haw ahorow wɔ afã horow a ɛyɛ den kɛse mu (te sɛ yɛn nsɛm a wɔde hyɛ mu akuw, bɔtn akuw, ne nea ɛkeka ho). - Popovers a wɔbɛkanyan wɔ nneɛma a ahintaw so no rennyɛ adwuma.
- Ɛsɛ sɛ wɔkanyan popovers ma
.disabled
anaadisabled
element ahorow wɔ wrapper element bi so. - Sɛ wɔkanyan no fi nhama a ɛkyekyere nsensanee pii so a, popovers no bɛkɔ mfinimfini wɔ ankora no nyinaa trɛw ntam. Fa di dwuma
.text-nowrap
wɔ wo<a>
s so na woakwati saa suban yi. - Ɛsɛ sɛ wɔde popovers sie ansa na wɔayi wɔn nneɛma a ɛne no hyia no afi DOM no mu.
- Popovers betumi akanyan aseda element bi a ɛwɔ sunsuma DOM mu.
prefers-reduced-motion
media asɛmmisa no so. Hwɛ
yɛn akwan a wɔfa so nya nneɛma ho nkrataa no fã a wɔatew so no .
Kɔ so kenkan na hwɛ sɛnea popovers de nhwɛso ahorow bi yɛ adwuma.
Nhwɛso: Ma popovers nyɛ adwuma wɔ baabiara
Ɔkwan baako a wobɛfa so ahyɛ popovers nyinaa ase wɔ krataafa bi so ne sɛ wobɛpaw wɔn denam wɔn data-toggle
su so:
$(function () {
$('[data-toggle="popover"]').popover()
})
Nhwɛso: Sɛ wode container
option no bedi dwuma
Sɛ wowɔ style ahorow bi wɔ ɔwofo element bi so a ɛtwetwe popover bi a, wobɛpɛ sɛ wokyerɛ amanneɛbɔ bi sɛnea container
ɛbɛyɛ a popover no HTML bɛda adi wɔ saa element no mu mmom.
$(function () {
$('.example-popover').popover({
container: 'body'
})
})
Nhwɛsoɔ
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
Akwankyerɛ anan
Nneɛma anan wɔ hɔ a wubetumi apaw: atifi, nifa, ase, ne benkum a wɔahyehyɛ no pɛpɛɛpɛ.
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="top" data-content="Top popover">
Popover on top
</button>
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="right" data-content="Right popover">
Popover on right
</button>
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Bottom popover">
Popover on bottom
</button>
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="left" data-content="Left popover">
Popover on left
</button>
Dismiss wɔ klik a edi hɔ no so
Fa focus
trigger no di dwuma fa yi popovers wɔ ɔdefo no klik a edi hɔ a ɛfa element soronko bi ho sen toggle element no so.
Markup pɔtee a ɛho hia ma dismiss-on-next-click
Sɛ wopɛ sɛ wobɔ cross-browser ne cross-platform suban yiye a, ɛsɛ sɛ wode <a>
tag no di dwuma, ɛnyɛ tag no <button>
, na ɛsɛ sɛ wode tabindex
attribute nso ka ho.
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-toggle="popover" data-trigger="focus" title="Dismissible popover" data-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
$('.popover-dismiss').popover({
trigger: 'focus'
})
Nneɛma a wɔadi dɛm
Elements a ɛwɔ disabled
attribute no nyɛ nkitahodi, a ɛkyerɛ sɛ wɔn a wɔde di dwuma no ntumi nkɔ so anaasɛ wɔnkyere wɔn mfa nhyɛ popover (anaasɛ adwinnade ho nsɛm). Sɛ́ adwuma no, wobɛpɛ sɛ wokanyan popover no fi wrapper bi mu <div>
anaasɛ <span>
na wubu so pointer-events
wɔ element a wɔadi dɛm no so.
Wɔ popover triggers a wɔadi dɛm ho no, ebia wobɛpɛ nso data-trigger="hover"
sɛnea ɛbɛyɛ a popover no bɛda adi sɛ nsɛm a wɔde aniwa hu ntɛm ara ma wo dwumadiefoɔ no sɛdeɛ ebia wɔrenhwɛ kwan sɛ wɔbɛkliki element a wɔadi dɛm so.
<span class="d-inline-block" data-toggle="popover" data-content="Disabled popover">
<button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
</span>
Sɛnea wɔde di dwuma
Ma popovers nyɛ adwuma denam JavaScript so:
$('#example').popover(options)
GPU a ɛma nneɛma yɛ ntɛmntɛm
Ɛtɔ da bi a, Popovers da adi sɛ ɛyɛ blurry wɔ Windows 10 mfiri ahorow so esiane GPU ahoɔhare ne nhyehyɛe DPI a wɔasesa nti. Workaround ma eyi wɔ v4 mu ne sɛ wobɛma GPU acceleration ayɛ adwuma sɛnea ɛho hia wɔ wo popovers so.
Nsiesiei a wɔahyɛ ho nyansa:
Popper.Defaults.modifiers.computeStyle.gpuAcceleration = !(window.devicePixelRatio < 1.5 && /Win/.test(navigator.platform))
Popovers a wɔbɛma ayɛ adwuma ama keyboard ne mfiridwuma a ɛboa wɔn a wɔde di dwuma no
Sɛ wobɛma keyboard dwumadiefoɔ atumi ayɛ wo popovers no adwuma a, ɛsɛ sɛ wode ka HTML elements a ɛyɛ atetesɛm no keyboard-focusable ne nkitahodiɛ (te sɛ links anaa form controls) nko ara. Ɛwom sɛ wobetumi ama HTML nneɛma a wɔpɛ (te sɛ <span>
s) ayɛ nea wɔde wɔn adwene si so denam tabindex="0"
su no a wɔde bɛka ho so de, nanso eyi bɛma tab gyinabea ahorow a ebetumi ayɛ abufuw na ɛyɛ basaa bɛka nneɛma a ɛnyɛ nkitahodi ho ama keyboard dwumadiefoɔ, na mfiridwuma a ɛboa dodoɔ no ara mprempren mmɔ popover no mu nsɛm ho amanneɛ wɔ saa tebea yi mu . Bio nso, mfa wo ho nto so nkutoo hover
sɛ nea ɛkanyan wo popovers no, efisɛ eyi bɛma ayɛ den sɛ ɛbɛkanyan wɔn a wɔde keyboard di dwuma no.
Bere a wubetumi de HTML a ɛyɛ fɛ, a wɔahyehyɛ no ahyɛ popovers mu a html
wobɛpaw no, yɛhyɛ nyansa denneennen sɛ kwati sɛ wode nsɛm a ɛboro so bɛka ho. Ɔkwan a popovers fa so yɛ adwuma mprempren ne sɛ, sɛ wɔda no adi wie a, wɔde wɔn nsɛm no kyekyere trigger element a ɛwɔ aria-describedby
attribute no ho. Ne saa nti, wɔde popover no mu nsɛm nyinaa bɛto gua akyerɛ wɔn a wɔde mfiridwuma ho nimdeɛ a ɛboa di dwuma no sɛ nsu tenten biako a wontwa mu.
Bio nso, bere a ɛyɛ yiye sɛ wode nkitahodi controls (te sɛ form elements anaa links) nso bɛka wo popover no ho (denam saa elements yi a wode bɛka whiteList
attributes ne tags anaa wɔama ho kwan no ho) no, hu sɛ mprempren popover no nhwɛ keyboard focus nhyehyɛe no so. Sɛ keyboard dwumadie bi bue popover a, adwene kɔ so tra triggering element no so, na sɛdeɛ popover no taa nni trigger no akyi ntɛm ara wɔ document no nhyehyɛɛ mu no, biribiara nni hɔ a ɛkyerɛ sɛ wobɛkɔ anim/abɛmiaTABbɛma obi a ɔde keyboard di dwuma akɔ popover no ankasa mu. Ne tiawa mu no, sɛ wode nkitahodi controls ka popover ho kɛkɛ a, ɛbɛyɛ sɛ ɛbɛma saa controls yi ayɛ nea wontumi nkɔ/wɔrentumi mfa nni dwuma mma wɔn a wɔde keyboard di dwuma ne wɔn a wɔde mfiridwuma a ɛboa di dwuma, anaasɛ anyɛ yiye koraa no, ɛbɛma wɔanya nhyehyɛe a wɔde wɔn adwene si so nyinaa a ntease nnim. Wɔ saa nsɛm yi mu no, susuw ho sɛ wode modal nkɔmmɔbɔ bedi dwuma mmom.
Nneɛma a wubetumi apaw
Wobetumi afa data attributes anaa JavaScript so de nneɛma a wobɛpaw no akɔ. Sɛ wopɛ data su ahorow a, fa option din no ka ho data-
, sɛnea ɛwɔ data-animation=""
.
sanitize
,
sanitizeFn
ne
whiteList
options no ntumi mfa data attributes mfa mma.
Din | Korɔ | Mfiaseɛ | Nkyerɛmu |
---|---|---|---|
animation a wɔde yɛ nneɛma | boolean ho asɛm | nokorɛ | Fa CSS fade nsakrae bi di dwuma wɔ popover no so |
ade a wɔde gu mu | ahama | element | ɛnyɛ ampa | ɛnyɛ ampa | Ɛde popover no ka element pɔtee bi ho. Nhwɛso: |
emu nsɛm | ahama | element | dwumadie | '' . | Default content value sɛ Sɛ wɔde dwumadie bi ma a, wɔbɛfrɛ no a ne |
ka akyi | nɔma | adeɛ | 0 na ɛwɔ hɔ | Delay kyerɛ na wɔde sie popover (ms) - no mfa manual trigger type ho Sɛ wɔde nɔma bi ma a, wɔde delay di dwuma wɔ hide/show abien no nyinaa mu Ade nhyehyɛe ne: |
html na ɛwɔ hɔ | boolean ho asɛm | ɛnyɛ ampa | Fa HTML hyɛ popover no mu. Sɛ ɛyɛ atoro a, wɔde jQuery text kwan no bedi dwuma de ahyɛ nsɛm a ɛwɔ DOM no mu. Fa text di dwuma sɛ XSS ntua ho asɛm haw wo a. |
a wɔde bɛto hɔ | ahama | dwumadie | 'nifa' | Sɛnea wɔde popover no si hɔ - auto | soro | ase hɔ | benkum so | nifa. Sɛ wɔde dwumadie bi di dwuma de kyerɛ beaeɛ a wɔde bɛto a, wɔfrɛ no a popover DOM node no yɛ ne akyinnyegyeɛ a ɛdi kan na triggering element DOM node yɛ ne deɛ ɛtɔ so mmienu. Wɔde |
nea ɔpaw ade | ahama | ɛnyɛ ampa | ɛnyɛ ampa | Sɛ wɔde selector bi ma a, wɔde popover nneɛma bɛhyɛ botae ahorow a wɔakyerɛ no nsa. Wɔ nneyɛe mu no, wɔde eyi di dwuma de ma HTML nsɛm a ɛyɛ nnam no tumi nya popovers a wɔde aka ho. Hwɛ eyi ne nhwɛso a ɛma nsɛm pii . |
nsusuwso | ahoma | '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>' |
Base HTML a wode bedi dwuma bere a woreyɛ popover no. Wɔde popover no Wɔde popover no
Ɛsɛ sɛ wrapper element a ɛwɔ akyi paa no nya |
atiti asɛm | ahama | element | dwumadie | '' . | Default title value sɛ Sɛ wɔde dwumadie bi ma a, wɔbɛfrɛ no a ne |
nkanyan | ahoma | 'kliki'. | Sɛnea popover no fi ase - klik | hover | adwene a wɔde si biribi so | akwankyerɛ. Wubetumi atwam wɔ nneɛma pii a ɛkanyan adwene mu; fa ahunmu tetew wɔn mu. manual wontumi mfa nkata ade foforo biara a ɛkanyan no ho. |
offset a wɔde hyɛ mu | nɔma | ahoma | 0 na ɛwɔ hɔ | Offset a popover no toto ne botae no ho. Sɛ wopɛ nsɛm pii a hwɛ Popper's offset docs . |
fallbackNsɛm a wɔde si hɔ | ahama | array a ɛwɔ hɔ | 'dane' | Ma kwan ma wɔnkyerɛ gyinabea a Popper de bedi dwuma wɔ fallback so. Sɛ wopɛ nsɛm pii a hwɛ Popper's behavior docs |
amanneAdesuakuw | ahama | dwumadie | '' . | Fa adesua ahorow ka popover no ho bere a wɔakyerɛ no. Hyɛ no nsow sɛ wɔde saa adesua ahorow yi bɛka adesua ahorow biara a wɔakyerɛ wɔ nsusuwso no mu no ho. Sɛ wode adesua ahorow pii bɛka ho a, fa ahunmu tetew mu: Wubetumi nso de dwumadie bi a ɛsɛ sɛ ɛsan de ahama baako a adesua din foforɔ wom ba no atwam. |
ɔhye so | ahama | adeɛ | 'scrollƆwofo'. | Overflow constraint hye a ɛwɔ popover no mu. Gye 'viewport' , 'window' , 'scrollParent' , anaa HTMLElement nkyerɛkyerɛmu bi (JavaScript nkutoo) botae ahorow tom. Sɛ wopɛ nsɛm pii a hwɛ Popper preventOverflow docs . |
sanitize yɛ adwuma | boolean ho asɛm | nokorɛ | Ma sanitization no nyɛ adwuma anaasɛ ɛnnyɛ adwuma. If activated 'template' , 'content' na 'title' options no bɛyɛ sanitized. Hwɛ sanitizer ɔfã no wɔ yɛn JavaScript nkrataa mu . |
whiteList a ɛwɔ hɔ | adeɛ | Default bo a ɛsom | Adeɛ a ɛwɔ su ne tags a wɔama ho kwan |
sanitizeFn a wɔde yɛ ahotew | null | dwumadie | ohunu | Ɛha na wubetumi de w’ankasa sanitize adwuma ama. Eyi betumi ayɛ nea mfaso wɔ so sɛ wopɛ sɛ wode nhomakorabea a wɔatu ho ama di dwuma de yɛ ahotew a. |
popperNhyehyɛe no | null | adeɛ | ohunu | Sɛ wopɛ sɛ wo sesa Bootstrap no Popper nhyehyeɛ a ɛwɔ hɔ no a, hwɛ Popper nhyehyeɛ |
Data su ahorow a ɛfa ankorankoro popovers ho
Wobetumi akyerɛ akwan foforo a wɔbɛfa so akyerɛ ankorankoro popovers denam data su ahorow a wɔde bedi dwuma so, sɛnea wɔakyerɛkyerɛ mu wɔ atifi hɔ no.
Akwan a wɔfa so yɛ
Asynchronous akwan ne nsakrae ahorow
API akwan nyinaa yɛ asynchronous na ɛhyɛ nsakrae ase . Wɔsan kɔ nea ɔfrɛɛ no no nkyɛn bere a wɔafi nsakrae no ase ara pɛ nanso ansa na aba awiei . Bio nso, wobebu ani agu ɔkwan a wɔfa so frɛ ade bi a ɛresakra so no so .
$().popover(options)
Fi ase popovers ma element ahorow a wɔaboaboa ano.
.popover('show')
Ɛda element bi popover adi. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔada popover no adi ankasa (kyerɛ sɛ ansa na shown.bs.popover
asɛm no asi). Wobu eyi sɛ “nsaano” a wɔde kanyan popover no. Popovers a wɔn asɛmti ne emu nsɛm nyinaa yɛ zero-length no, wɔmfa nkyerɛ da.
$('#element').popover('show')
.popover('hide')
Fa element bi popover no sie. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔde popover no asie ankasa (kyerɛ sɛ ansa na hidden.bs.popover
asɛm no asi). Wobu eyi sɛ “nsaano” a wɔde kanyan popover no.
$('#element').popover('hide')
.popover('toggle')
Toggles element bi popover. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔakyerɛ popover no ankasa anaa wɔde asie (kyerɛ sɛ ansa na shown.bs.popover
anaa hidden.bs.popover
adeyɛ no aba). Wobu eyi sɛ “nsaano” a wɔde kanyan popover no.
$('#element').popover('toggle')
.popover('dispose')
Hide na ɛsɛe element bi popover. Popovers a ɛde delegation di dwuma (a wɔbɔ denam option noselector
so ) no ntumi nsɛe no ankorankoro wɔ descendant trigger elements so.
$('#element').popover('dispose')
.popover('enable')
Ɛma element bi popover tumi a wɔde bɛkyerɛ. Popovers no yɛ adwuma default so.
$('#element').popover('enable')
.popover('disable')
Yi tumi a ɛwɔ hɔ ma element bi popover a wɔbɛda no adi no fi hɔ. Sɛ wɔsan de yɛ adwuma nkutoo a, wobetumi akyerɛ popover no.
$('#element').popover('disable')
.popover('toggleEnabled')
Toggles tumi a ɛma element bi popover bɛkyerɛ anaa wɔde asie.
$('#element').popover('toggleEnabled')
.popover('update')
Updates gyinabea a element bi popover wɔ.
$('#element').popover('update')
Nsɛm a esisi
Nsɛm a Ɛsisii no Su | Nkyerɛmu |
---|---|
kyerɛ.bs.popover | Saa adeyɛ yi tow ntɛm ara bere a show wɔfrɛ instance kwan no. |
wɔakyerɛ.bs.popover | Wɔtow saa adeyɛ yi bere a wɔayɛ popover no ahu nea ɔde di dwuma no (bɛtwɛn ma CSS nsakrae ahorow no awie). |
hide.bs.popover a ɛwɔ hɔ no | Wɔtow saa adeyɛ yi ntɛm ara bere a hide wɔafrɛ instance kwan no. |
ahintaw.bs.ohia | Wɔtow saa adeyɛ yi bere a popover no awie a wɔde asie ama ɔdefo no (bɛtwɛn ma CSS nsakrae ahorow no awie). |
wɔde ahyɛ mu.bs.popover | Wɔtow saa adeyɛ yi wɔ adeyɛ no akyi show.bs.popover bere a wɔde popover template no aka DOM no ho. |
$('#myPopover').on('hidden.bs.popover', function () {
// do something...
})