Nnwinnade Ho Afotu
Nwoma ne nhwɛsoɔ a wɔde bɛka Bootstrap adwinnadeɛ a wɔahyɛ da ayɛ ho a CSS ne JavaScript de CSS3 di dwuma ma animations ne data-bs-attributes ma local title storage.
Nsɛm a Wɔaka abom
Nneɛma a ɛsɛ sɛ wuhu bere a wode tooltip plugin no redi dwuma no:
- Nnwinnade ho nsɛm de ne 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 adwinnade ho nsɛm atumi ayɛ adwuma! - Tooltips yɛ opt-in esiane adwumayɛ nti, enti ɛsɛ sɛ w’ankasa wufi ase .
- Nnwinnade ho nsɛm a ɛwɔ asɛmti a ne tenten yɛ zero no nkyerɛ 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). - Nnwinnade ho nsɛm a wobɛkanyan wɔ nneɛma a ahintaw so no rennyɛ adwuma.
- Ɛsɛ sɛ wɔde adwinnade afotu ma
.disabled
anaadisabled
element ahorow no fi ase wɔ wrapper element bi so. - Sɛ wofi ase fi hyperlink ahorow a ɛtrɛw nkyerɛwde ahorow pii mu a, adwinnade ho nsɛm bɛkɔ mfinimfini. Fa di dwuma
white-space: nowrap;
wɔ wo<a>
s so na woakwati saa suban yi. - Ɛsɛ sɛ wɔde nnwinnadeɛ ho nsɛm sie ansa na wɔayi wɔn nneɛma a ɛne no hyia no afiri DOM no mu.
- Tooltips betumi ayɛ triggered 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 .
Woanya saa nneɛma no nyinaa? Ɔkɛseɛ, ma yɛnhwɛ sɛdeɛ wɔde nhwɛsoɔ bi yɛ adwuma.
Nhwɛso: Ma adwinnade ho nsɛm nyɛ adwuma wɔ baabiara
Ɔkwan baako a wobɛfa so ahyɛ adwinnadeɛ a ɛwɔ kratafa bi so nyinaa ase ne sɛ wobɛpaw wɔn denam wɔn data-bs-toggle
su so:
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
Nhwɛso ahorow
Fa wo nsa hyɛ link ahorow a ɛwɔ ase ha no so na wubehu nnwinnade ho nyansahyɛ ahorow:
Beaeɛ nsɛm a wɔde bɛkyerɛ inline links bi a ɛwɔ adwinnadeɛ ho nkyerɛkyerɛmu. Mprempren eyi yɛ filler ara kwa, owudifo biara nni hɔ. Nsɛm a wɔde ahyɛ ha sɛnea ɛbɛyɛ a wobesuasua nkyerɛwee ankasa a ɛwɔ hɔ no ara kwa . Na ne nyinaa sɛnea ɛbɛyɛ a wubenya adwene wɔ sɛnea nnwinnade ho nyansahyɛ ahorow bɛyɛ bere a wɔde di dwuma wɔ wiase tebea horow ankasa mu no ho ara kwa. Enti anidasoɔ wɔ mu sɛ seesei woahunu sɛdeɛ saa nnwinnadeɛ a ɛwɔ links so yi bɛtumi ayɛ adwuma wɔ nneyɛeɛ mu, berɛ a wode adi dwuma wɔ w’ankasa wo site anaa project so no.
Fa wo nsa hyɛ bɔtn a ɛwɔ ase hɔ no so na wubehu adwinnade ho akwankyerɛ anan no: soro, nifa, ase, ne benkum. Akwankyerɛ ahorow no yɛ ahwehwɛ bere a wode Bootstrap redi dwuma wɔ RTL mu no.
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">
Tooltip on top
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">
Tooltip on right
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tooltip on bottom">
Tooltip on bottom
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" title="Tooltip on left">
Tooltip on left
</button>
Na ɛne HTML a wɔahyɛ da ayɛ a wɔde aka ho no:
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
Tooltip with HTML
</button>
Sɛ wode SVG di dwuma a:
Sass
Nneɛma a Ɛsakra
$tooltip-font-size: $font-size-sm;
$tooltip-max-width: 200px;
$tooltip-color: $white;
$tooltip-bg: $black;
$tooltip-border-radius: $border-radius;
$tooltip-opacity: .9;
$tooltip-padding-y: $spacer * .25;
$tooltip-padding-x: $spacer * .5;
$tooltip-margin: 0;
$tooltip-arrow-width: .8rem;
$tooltip-arrow-height: .4rem;
$tooltip-arrow-color: $tooltip-bg;
Sɛnea wɔde di dwuma
Adwinnade ho nkyerɛkyerɛmu plugin no yɛ nsɛm ne agyiraehyɛde wɔ ahwehwɛde so, na sɛnea ɛte no, ɛde adwinnade ho nsɛm si wɔn trigger element no akyi.
Fa JavaScript so na ɛkanyan adwinnade no:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, options)
Overflow auto
nescroll
Tooltip gyinabea bɔ mmɔden sɛ ɛbɛsakra ne ho bere a ɔwofo container wɔ overflow: auto
anaa overflow: scroll
ɛte yɛn .table-responsive
, nanso ɛda so ara kura mfitiase beae no gyinabea. Sɛ wopɛ sɛ wosiesie eyi a, hyehyɛ boundary
nhyehyɛe no (ma flip modifier a ɔde popperConfig
option no bedi dwuma) wɔ HTMLElement biara so de abɔ default value no so, 'clippingParents'
, te sɛ document.body
:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, {
boundary: document.body // or document.querySelector('#boundary')
})
Markup a wɔde hyɛ agyirae
Agyiraehyɛde a wɔhwehwɛ ma adwinnade ho nkyerɛkyerɛmu no yɛ data
su bi nkutoo na title
wɔ HTML element no so no wopɛ sɛ wunya adwinnade ho nsɛm. Nnwinnade bi agyiraehyɛde a wɔayɛ no yɛ mmerɛw mmom, ɛwom sɛ ɛhwehwɛ gyinabea (default no, wɔde ahyɛ mu top
denam plugin no so).
Nnwinnade ho nkyerɛkyerɛmu a wɔbɛma ayɛ adwuma ama keyboard ne mfiridwuma a ɛboa wɔn a wɔde di dwuma no
Ɛsɛ sɛ wode nnwinnadeɛ ho nkyerɛkyerɛmu ka HTML nneɛma a ɛyɛ atetesɛm no keyboard-focusable ne nkitahodiɛ (te sɛ links anaa form controls) nko ara ho. Ɛ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 mprempren mmoa mfiridwuma dodow no ara mfa adwinnade no ho asɛm mma wɔ tebea yi mu. Bio nso, mfa wo ho nto so hover
sɛ ɛno nkutoo na ɛbɛkanyan wo adwinnade ho nyansahyɛ no, efisɛ eyi bɛma wo adwinnade ho nsɛm no anyɛ yiye sɛ ɛbɛkanyan wɔn a wɔde keyboard di dwuma no.
<!-- HTML to write -->
<a href="#" data-bs-toggle="tooltip" title="Some tooltip text!">Hover over me</a>
<!-- Generated markup by the plugin -->
<div class="tooltip bs-tooltip-top" role="tooltip">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner">
Some tooltip text!
</div>
</div>
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 mfa wɔn adwene nsi wɔn so, wɔmfa wɔn ho nhyɛ mu, anaasɛ wɔmfa wɔn nsa nka wɔn mfa nhyɛ adwinnade ho nsɛm (anaasɛ popover) ase. Sɛ́ ɔkwan a wobɛfa so ayɛ adwuma no, wobɛpɛ sɛ wokanyan adwinnade no asɛm no fi wrapper <div>
anaa <span>
, a eye sen biara a wɔayɛ no keyboard-focusable denam tabindex="0"
.
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" title="Disabled tooltip">
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>
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-bs-
, sɛnea ɛwɔ data-bs-animation=""
. Hwɛ sɛ wobɛsesa case type a ɛwɔ option din no mu afi camelCase akɔ kebab-case bere a wode options no nam data attributes so retwam no. Sɛ nhwɛso no, sɛ́ anka wode bedi dwuma data-bs-customClass="beautifier"
no, fa data-bs-custom-class="beautifier"
.
sanitize
,
sanitizeFn
, ne
options no mma.allowList
Din | Korɔ | Mfiaseɛ | Nkyerɛmu |
---|---|---|---|
animation |
boolean ho asɛm | true |
Fa CSS fade nsakrae bi di dwuma wɔ adwinnade no ho |
container |
ahama | element | ɛnyɛ ampa | false |
Fa adwinnade no ho nkyerɛkyerɛmu no ka element pɔtee bi ho. Nhwɛso: |
delay |
nɔma | adeɛ | 0 |
Delay kyerɛ na wɔde sie tooltip (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ɛɛ ne: |
html |
boolean ho asɛm | false |
Ma HTML kwan wɔ adwinnade no mu. Sɛ ɛyɛ nokware a, HTML tags a ɛwɔ adwinnade no mu no Fa text di dwuma sɛ XSS ntua ho asɛm haw wo a. |
placement |
ahama | dwumadie | 'top' |
Sɛnea wɔde adwinnade 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 adwinnadeɛ tip DOM node yɛ ne asɛm a ɛdi kan na triggering element DOM node yɛ nea ɛtɔ so mmienu. Wɔde |
selector |
ahama | ɛnyɛ ampa | false |
Sɛ wɔde selector bi ma a, wɔde tooltip nneɛma bɛhyɛ botae ahorow a wɔakyerɛ no nsa. Wɔ nneyɛe mu no, wɔde eyi nso di dwuma de nnwinnade ho nsɛm nso di dwuma wɔ DOM nneɛma a wɔde aka ho wɔ ɔkwan a ɛyɛ nnam so ( jQuery.on mmoa). Hwɛ eyi ne nhwɛso a ɛma nsɛm pii . |
template |
ahoma | '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' |
Base HTML a wode bedi dwuma bere a woreyɛ adwinnade no ho nsɛm. Wɔde adwinnade no
Ɛsɛ sɛ wrapper element a ɛwɔ akyi paa no nya |
title |
ahama | element | dwumadie | '' |
Default title value sɛ Sɛ wɔde dwumadie bi ma a, wɔbɛfrɛ no a ne |
trigger |
ahoma | 'hover focus' |
Sɛnea wɔde adwinnade tip no hyɛ 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.
|
fallbackPlacements |
array a ɛwɔ hɔ | ['top', 'right', 'bottom', 'left'] |
Kyerɛkyerɛ fallback placements mu denam placements list a wode bɛma wɔ array mu (sɛnea wopɛ nnidiso nnidiso). Sɛ wopɛ nsɛm pii a hwɛ Popper's behavior docs |
boundary |
ahama | adeɛ | 'clippingParents' |
Overflow anohyeto hye a ɛwɔ adwinnade no ano (ɛfa Popper preventOverflow modifier nkutoo ho). Sɛnea wɔahyɛ no ɛyɛ 'clippingParents' na ebetumi agye HTMLElement nkyerɛkyerɛmu (ɛnam JavaScript nkutoo so). Sɛ wopɛ nsɛm pii a hwɛ Popper detectOverflow docs . |
customClass |
ahama | dwumadie | '' |
Fa adesua ahorow ka adwinnade 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. |
sanitize |
boolean ho asɛm | true |
Ma sanitization no nyɛ adwuma anaasɛ ɛnnyɛ adwuma. Sɛ activated 'template' na 'title' options bɛyɛ sanitized. Hwɛ sanitizer ɔfã no wɔ yɛn JavaScript nkrataa no mu . |
allowList |
adeɛ | Default bo a ɛsom | Adeɛ a ɛwɔ su ne tags a wɔama ho kwan |
sanitizeFn |
null | dwumadie | null |
Ɛ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. |
offset |
nhyehyeɛ | ahama | dwumadie | [0, 0] |
Offset a ɛwɔ adwinnade no a wɔde toto ne botae no ho. Wubetumi de ahama bi akɔ data su ahorow mu a ɛwɔ botae ahorow a wɔatew mu wɔ koma mu te sɛ: Sɛ wɔde dwumadie bi di dwuma de kyerɛ offset no a, wɔde adeɛ bi a ɛwɔ popper placement, reference, ne popper rects sɛ ne argument a ɛdi kan no frɛ no. Wɔde triggering element DOM node no twam sɛ akyinnyegye a ɛto so abien. Ɛsɛ sɛ dwumadie no san de array a ɛwɔ nɔma mmienu ba: . Sɛ wopɛ nsɛm pii a hwɛ Popper's offset docs . |
popperConfig |
null | ade | dwumadie | null |
Sɛ wopɛ sɛ wosakra Bootstrap no Popper nhyehyɛe a ɛwɔ hɔ dedaw no a, hwɛ Popper nhyehyɛe . Sɛ wɔde dwumadie bi di dwuma de yɛ Popper nhyehyeɛ no a, wɔde adeɛ bi a ɛwɔ Bootstrap no Popper nhyehyeɛ a ɛwɔ hɔ dedaw no frɛ no. Ɛboa wo ma wode default no di dwuma na wode bom ne w’ankasa nhyehyɛe. Ɛsɛ sɛ dwumadie no san de nhyehyɛɛ adeɛ bi ba ma Popper. |
Data su ahorow ma ankorankoro nnwinnade ho nkyerɛkyerɛmu
Wobetumi akyerɛ akwan foforo a wɔbɛfa so akyerɛ ankorankoro adwinnade ho nkyerɛkyerɛmu denam data su ahorow a wɔde bedi dwuma so, sɛnea wɔakyerɛkyerɛ mu wɔ atifi hɔ no.
Dwumadi a wɔde di dwuma nepopperConfig
var tooltip = new bootstrap.Tooltip(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
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 .
da no adi
Ɛda element bi adwinnade ho nsɛm adi. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔada adwinnade no adi ankasa (kyerɛ sɛ ansa na shown.bs.tooltip
asɛm no asi). Wobu eyi sɛ “nsaano” a wɔde kanyan adwinnade no ho asɛm. Nnwinnade ho nsɛm a ɛwɔ asɛmti a ne tenten yɛ zero no nkyerɛ da.
tooltip.show()
tɛ
Fa element bi adwinnade ho nsɛm sie. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔde adwinnade no asie ankasa (kyerɛ sɛ ansa na hidden.bs.tooltip
asɛm no asi). Wobu eyi sɛ “nsaano” a wɔde kanyan adwinnade no ho asɛm.
tooltip.hide()
toggle no
Toggles element bi adwinnade ho nsɛm. San kɔ nea ɔfrɛ no no nkyɛn ansa na wɔakyerɛ adwinnade no asɛm no ankasa anaa wɔde asie (kyerɛ sɛ ansa na shown.bs.tooltip
anaa hidden.bs.tooltip
adeyɛ no aba). Wobu eyi sɛ “nsaano” a wɔde kanyan adwinnade no ho asɛm.
tooltip.toggle()
tow gu
Hide na ɛsɛe element bi adwinnade tip (Eyi data a wɔde asie wɔ DOM element no so). Nnwinnade a wɔde delegation di dwuma (a wɔde option ) na ɛyɛe noselector
ntumi nsɛe no ankorankoro wɔ descendant trigger elements so.
tooltip.dispose()
ma kwan
Ɛma element bi tooltip tumi a wɔde bɛkyerɛ. Nnwinnade ho nsɛm no yɛ nea wɔahyɛ da ayɛ.
tooltip.enable()
sɛe
Yi tumi a ɛwɔ element bi adwinnade a wɔde bɛkyerɛ no fi hɔ. Sɛ wɔsan yɛ adwuma nkutoo a, wobetumi akyerɛ adwinnade no.
tooltip.disable()
toggleWɔama ayɛ adwuma
Toggles tumi a element bi adwinnade tip bɛkyerɛ anaa wɔde asie.
tooltip.toggleEnabled()
sakra mu
Ɔyɛ element bi adwinnade tip no gyinabea foforo.
tooltip.update()
nyaNhwɛsode
Static kwan a ɛma wo kwan ma wo nya tooltip instance a ɛbata DOM element bi ho
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
nyaAnaasɛKyɛNhwɛso
Static kwan a ɛma wo kwan ma wo nya tooltip instance a ɛbata DOM element bi ho, anaasɛ wobɔ foforo sɛ ɛba sɛ wɔanhyɛ aseɛ a
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
Nsɛm a esisi
Adeyɛ no su | Nkyerɛmu |
---|---|
show.bs.tooltip |
Saa adeyɛ yi tow ntɛm ara bere a show wɔfrɛ instance kwan no. |
shown.bs.tooltip |
Wɔtow saa adeyɛ yi bere a wɔayɛ adwinnade no nkyerɛkyerɛmu no ahu nea ɔde di dwuma no (bɛtwɛn ma CSS nsakrae ahorow no awie). |
hide.bs.tooltip |
Wɔtow saa adeyɛ yi ntɛm ara bere a hide wɔafrɛ instance kwan no. |
hidden.bs.tooltip |
Wɔtow saa adeyɛ yi bere a wɔawie adwinnade no nsɛm a wɔde asie ama ɔdefo no (bɛtwɛn ma CSS nsakrae ahorow no awie). |
inserted.bs.tooltip |
Wɔtow saa adeyɛ yi wɔ adeyɛ no akyi show.bs.tooltip bere a wɔde adwinnade nkyerɛkyerɛmu nsusuwso no aka DOM no ho. |
var myTooltipEl = document.getElementById('myTooltip')
var tooltip = new bootstrap.Tooltip(myTooltipEl)
myTooltipEl.addEventListener('hidden.bs.tooltip', function () {
// do something...
})
tooltip.hide()