Tultip dɛn fɔ yuz
Dokumɛnt ɛn ɛgzampul fɔ ad kɔstɔm Bootstrap tultip dɛn wit CSS ɛn JavaSkript we de yuz CSS3 fɔ animashɔn ɛn data-bs-atribyut fɔ lokal taytul stɔrɔj.
Ɔvaviu fɔ di Baybul
Tin dɛn fɔ no we yu de yuz di tultip plɔgin:
- Tultip dɛn de abop pan di 3rd pati laybri Popper fɔ pozishɔn. Yu fɔ put popper.min.js bifo bootstrap.js ɔ yuz
bootstrap.bundle.min.js
/bootstrap.bundle.js
we gɛt Popper fɔ mek tultip dɛn wok! - Tultip dɛn na opt-in fɔ pefɔmɛns rizin, so yu fɔ initialize dɛn yusɛf .
- Tultip dɛn we gɛt taytul dɛn we nɔ gɛt ziro nɔ de ɛva sho.
- Spɛsify
container: 'body'
fɔ avɔyd fɔ rɛnd prɔblɛm dɛn na mɔ kɔmpleks kɔmpɔnɛnt dɛn (lɛk wi input grup dɛn, bɔtin grup dɛn, ɛn ɔda wan dɛn). - Fɔ trig tultip dɛn pan ɛlimɛnt dɛn we ayd nɔ go wok.
- Tultip fɔ
.disabled
ɔdisabled
ɛlimɛnt dɛn fɔ trig pan wan wrap ɛlimɛnt. - We dɛn trig am frɔm haypa link dɛn we de span bɔku layn dɛn, tultip dɛn go de na di sɛnt. Yuz
white-space: nowrap;
pan yu<a>
s fɔ avɔyd dis bihayvya. - Tultip dɛn fɔ ayd bifo dɛn dɔn pul dɛn kɔrɛspɔndɛns ɛlimɛnt dɛn na di DOM.
- Tultips kin trig tanks to wan elemɛnt insay wan shado DOM.
prefers-reduced-motion
midia kwɛstyɔn. Si di
ridyus muvmɛnt sɛkshɔn na wi aksesibiliti dɔkyumentri .
Yu get ol dat? Gret, mek wi si aw dɛn de wok wit sɔm ɛgzampul dɛn.
Example: Enable tultips evriwea
Wan we fɔ initialize ɔl di tultip dɛn na wan pej na fɔ pik dɛn bay dɛn data-bs-toggle
atribyut:
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
Ɛgzampul dɛn
Hova oba di link dɛn we de dɔŋ fɔ si tultip dɛn:
Pleshɔlda tɛks fɔ sho sɔm inlayn link dɛn wit tultip dɛn. Dis na naw jos filler, no kil. Kɔntinɛnt we dɛn put ya jɔs fɔ falamakata di prɛzɛns fɔ rial tɛks . Ɛn ɔl dat jɔs fɔ gi yu wan aidia bɔt aw tultip dɛn go luk we dɛn yuz dɛn na rial wɔl sityueshɔn dɛn. So wi op se yu dɔn si naw aw dɛn tultip dɛn ya na link dɛn kin wok na prɔsis, wans yu yuz dɛn na yu yon sayt ɔ prɔjek.
Hova oba di bɔtin dɛn we de dɔŋ fɔ si di 4 tultip dɛn dairekshɔn dɛn: ɔp, rayt, dɔŋ, ɛn lɛft. Dairekshɔn dɛn de mirɔ we yu de yuz Bootstrap na RTL.
<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>
Ɛn wit kɔstɔm HTML we dɛn ad:
<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>
Wit wan SVG:
Sass we bin de
Di tin dɛn we kin chenj
$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;
Aw fɔ yuz am
Di tultip plɔgin de jenarayz kɔntinyu ɛn mak pan dimand, ɛn bay difɔlt de put tultip dɛn afta dɛn trig ɛlimɛnt.
Trig di tultip bay JavaSkript:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, options)
Ovaflɔ auto
ɛnscroll
Tultip pozishɔn de tray fɔ chenj ɔtomɛtik wans wan mama ɛn papa kɔntena gɛt overflow: auto
ɔ overflow: scroll
lɛk wi .table-responsive
, bɔt stil de kip di ɔrijinal plesmɛnt in pozishɔn. Fɔ sɔlv dis, sɛt di boundary
opshɔn (fɔ di flip modifya we de yuz di popperConfig
opshɔn) to ɛni HTMLElement fɔ ɔvalayz di difɔlt valyu, 'clippingParents'
, lɛk document.body
:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, {
boundary: document.body // or document.querySelector('#boundary')
})
Mak-ap fɔ di tin dɛn we de apin
Di mak we yu nid fɔ wan tultip na jɔs wan data
atribyut ɛn title
na di HTML ɛlimɛnt yu want fɔ gɛt tultip. Di mak we dɛn dɔn mek fɔ wan tultip rili simpul, pan ɔl we i nid fɔ gɛt pozishɔn (bay difɔlt, top
di plɔgin sɛt to).
Mek tultip dɛn wok fɔ di wan dɛn we de yuz kibɔd ɛn ɛp tɛknɔlɔji
Yu fɔ jɔs ad tultip dɛn to HTML ɛlimɛnt dɛn we tradishɔnal wan we dɛn kin yuz fɔ pe atɛnshɔn pan kibɔd ɛn we kin wok wit ɔda pipul dɛn (lɛk link ɔ fɔm kɔntrol). Pan ɔl we dɛn kin mek arbitri HTML ɛlimɛnt dɛn (lɛk <span>
s) fɔs bay we dɛn ad di tabindex="0"
atribyut, dis go ad tab stɔp dɛn we kin anɔynt ɛn kɔnfyus pan ɛlimɛnt dɛn we nɔ de intaraktiv fɔ di wan dɛn we de yuz di kibɔd, ɛn bɔku pan di ɛtɛknɔlɔji dɛn we de ɛp pipul dɛn naw nɔ de anɔys di tultip na dis sityueshɔn. Apat frɔm dat, nɔ jɔs abop pan hover
as di trig fɔ yu tultip, bikɔs dis go mek yu tultip dɛn nɔ pɔsibul fɔ trig fɔ di wan dɛn we de yuz di kibɔd.
<!-- 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>
Di ɛlimɛnt dɛn we nɔ ebul fɔ wok
Elemɛnt dɛn wit di disabled
atribyut nɔ de intaraktiv, we min se yuzman dɛn nɔ kin ebul fɔ fos, hova, ɔ klik dɛn fɔ trig wan tultip (ɔ popover). As wokarawnd, yu go want fɔ trig di tultip frɔm wan wrapa <div>
ɔ <span>
, we fayn fɔ mek yu yuz 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>
Di tin dɛn we yu kin pik fɔ du
Yu kin pas opshɔn dɛn bay we yu yuz data atribyut ɔ JavaSkript. Fɔ data atribyut dɛn, ad di opshɔn nem to data-bs-
, lɛk insay data-bs-animation=""
. Mek shɔ se yu chenj di kes tayp fɔ di opshɔn nem frɔm camelCase to kebab-case we yu de pas di opshɔn dɛn via data atribyut dɛn. Fɔ ɛgzampul, bifo yu yuz data-bs-customClass="beautifier"
, yuz data-bs-custom-class="beautifier"
.
sanitize
,
sanitizeFn
, ɛn
allowList
opshɔn dɛn we yu de yuz di data atribyut dɛn.
Nem | Kayn | Balans | Tɔk bɔt |
---|---|---|---|
animation |
boolean we dɛn kɔl | true |
Aplay wan CSS fade transishɔn to di tultip |
container |
string fɔ di wan dɛn we de | elemɛnt | lay | false |
Apɛnd di tultip to wan patikyula ɛlimɛnt. Fɔ ɛgzampul: |
delay |
nɔmba | tin | 0 |
Dilay fɔ sho ɛn ayd di tultip (ms) - nɔ de aplay to manual trigger tayp If dɛn gi wan nɔmba, dɛn kin delay fɔ ɔl tu di ayd/sho Objekt strɔkchɔ na: |
html |
boolean we dɛn kɔl | false |
Alaw HTML na di tultip. If na tru, HTML tag dɛn na di tultip’s Yuz tɛks if yu de wɔri bɔt XSS atak dɛn. |
placement |
string fɔ di wan dɛn we de | wok | 'top' |
Aw fɔ posishun di tultip - ɔto | top | dɔŋ ya | lɛft | rayt. We dɛn yuz wan fɛnshɔn fɔ no di plesmɛnt, dɛn kin kɔl am wit di tultip DOM node as in fɔs argumɛnt ɛn di trigɛn ɛlimɛnt DOM node as in sɛkɔn. Di |
selector |
string fɔ di wan dɛn we de | lay | false |
If dɛn gi wan sɛlɛktɔ, dɛn go gi tultip ɔbjɛkt dɛn to di target dɛn we dɛn dɔn spɛsifa. In prɔsis, dɛn kin yuz dis fɔ yuz tultip dɛn bak to dinamik ad DOM ɛlimɛnt dɛn ( jQuery.on sɔpɔt). Si dis ɛn wan ɛgzampul we gɛt bɔku tin dɛn fɔ no bɔt . |
template |
rop | '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' |
Base HTML fɔ yuz we yu de mek di tultip. Di tultip dɛn
Di ɔtamost wrap ɛlimɛnt fɔ gɛt di |
title |
string fɔ di wan dɛn we de | elemɛnt | wok | '' |
Difɔlt taytul valyu if If dɛn gi wan fɛnshɔn, dɛn go kɔl am wit in |
trigger |
rop | 'hover focus' |
Aw di tultip de trig - klik | hover fɔ di wan dɛn we de wok | fɔs fɔs | buk. Yu kin pas bɔku trig dɛn; separet dɛn wit wan ples.
|
fallbackPlacements |
arenjmɛnt fɔ di wan dɛn we de | ['top', 'right', 'bottom', 'left'] |
Difayn fɔlbak plesmɛnt dɛn bay we yu gi wan list fɔ plesmɛnt dɛn na arenjmɛnt (in ɔda we aw dɛn lɛk). Fɔ no mɔ, luk na Popper’s behavior docs |
boundary |
string fɔ di wan dɛn we de | tin | 'clippingParents' |
Ovaflɔ kɔnstrakshɔn bɔda fɔ di tultip (i de aplay nɔmɔ to Popper in preventOverflow modifya). Bay difɔlt na 'clippingParents' ɛn kin aksept wan HTMLElement rɛfrɛns (via JavaSkript nɔmɔ). Fɔ no mɔ, luk na Popper’s detectOverflow docs . |
customClass |
string fɔ di wan dɛn we de | wok | '' |
Ad klas dɛn to di tultip we dɛn sho am. Notis se dɛn go ad dɛn klas ya apat frɔm ɛni klas we dɛn dɔn sho na di tɛmplat. Fɔ ad bɔku klas dɛn, separet dɛn wit spɛshal say dɛn: Yu kin pas wan fɛnshɔn bak we fɔ ritɔn wan string we gɛt ɔda klas nem dɛn. |
sanitize |
boolean we dɛn kɔl | true |
Enable ɔ disable di sanitayzeshɔn. If dɛn aktiv 'template' ɛn 'title' opshɔn dɛn go sanitayz. Si di say we se sanitiza na wi JavaSkript dɔkyumentri . |
allowList |
tin | Difɔlt valyu | Objek we gɛt atribyut ɛn tag dɛn we dɛn alaw |
sanitizeFn |
nul we de na di wɔl | wok | null |
Na ya yu kin saplae yu own sanitize function. Dis kin fayn if yu lɛk fɔ yuz laybri we dɛn dɔn gi yu fɔ du sanitayzeshɔn. |
offset |
arenjmɛnt fɔ | string fɔ di wan dɛn we de | wok | [0, 0] |
Ɔfset fɔ di tultip rilitiv to in target. Yu kin pas wan string insay data atribyut dɛn wit kɔma separet valyu dɛn lɛk: We dɛn yuz wan fɛnshɔn fɔ no di ɔfset, dɛn kin kɔl am wit wan ɔbjɛkt we gɛt di pɔpa plesmɛnt, di rɛfrɛns, ɛn di pɔpa rɛkt dɛn as in fɔs argumɛnt. Di trigεrin εlimεnt DOM node de pas as di sɛkɔn argumɛnt. Di fɛnshɔn fɔ ritɔn wan arenjmɛnt wit tu nɔmba dɛn: . Fɔ no mɔ, luk na Popper’s offset docs . |
popperConfig |
nul we de na di wɔl | ɔbjɛkt | wok | null |
Fɔ chenj Bootstrap in difɔlt Popper kɔnfigyushɔn, si Popper in kɔnfigyushɔn . We dɛn yuz wan fɛnshɔn fɔ mek di Popper kɔnfigyushɔn, dɛn kin kɔl am wit wan ɔbjɛkt we gɛt di Bootstrap in difɔlt Popper kɔnfigyushɔn. I de ɛp yu fɔ yuz ɛn jɔyn di difɔlt wit yu yon kɔnfigyushɔn. Di fɛnshɔn fɔ ritɔn wan kɔnfigyushɔn ɔbjɛkt fɔ Popa. |
Data atribyut fɔ wan wan tultip dɛn
Opshɔn fɔ wan wan tultip dɛn kin ɔda we fɔ spɛsifa tru di yus fɔ data atribyut dɛn, lɛk aw dɛn ɛksplen am ɔp.
Yuz funkshɔn witpopperConfig
var tooltip = new bootstrap.Tooltip(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Di we aw dɛn de du am
Asynchronous mεtכd dεm εn transishכn dεm
Ɔl di API mɛtɔd dɛn na asynchronous ɛn dɛn kin stat wan transishɔn . Dɛn kin go bak to di pɔsin we kɔl am jɔs lɛk aw dɛn bigin fɔ chenj bɔt bifo i dɔn . Apat frɔm dat, dɛn go ignore wan mɛtɔd kɔl pan wan transishɔn kɔmpɔnɛnt .
sho
Rivɛl wan ɛlimɛnt in tultip. Ritɔn to di pɔsin we kɔl bifo dɛn rili sho di tultip (dat na bifo di shown.bs.tooltip
tin apin). Dɛn kin tek dis as “manual” we de trig di tultip. Tultip dɛn we gɛt taytul dɛn we nɔ gɛt ziro nɔ de ɛva sho.
tooltip.show()
ayd
Ayd wan ɛlimɛnt in tultip. Ritɔn to di pɔsin we kɔl bifo di tultip dɔn rili ayd (dat na bifo di hidden.bs.tooltip
tin apin). Dɛn kin tek dis as “manual” we de trig di tultip.
tooltip.hide()
fɔ chenj di we aw dɛn de
Toggles wan element in tultip. Ritɔn to di pɔsin we kɔl bifo dɛn rili sho ɔ ayd di tultip (dat na bifo di shown.bs.tooltip
ɔ hidden.bs.tooltip
ivin apin). Dɛn kin tek dis as “manual” we de trig di tultip.
tooltip.toggle()
fɔ trowe am
Ayd ɛn pwɛl wan ɛlimɛnt in tultip (Rimov di data we dɛn dɔn kip na di DOM ɛlimɛnt). Tultip dɛn we de yuz delegɛshɔn (we dɛn mek yuz di selector
opshɔn ) nɔ kin ebul fɔ pwɛl wan wan pan disɛndant trig ɛlimɛnt dɛn.
tooltip.dispose()
ɛp
Gi wan elemɛnt in tultip di abiliti fɔ sho. Tultip dɛn de ɛnabul bay difɔlt.
tooltip.enable()
disebul
Rimov di abiliti fɔ wan ɛlimɛnt in tultip fɔ sho. Di tultip go jɔs ebul fɔ sho if dɛn dɔn ɛnabul am bak.
tooltip.disable()
toggleDɛn dɔn ɛnabul am
Toggles di abiliti fɔ wan elemɛnt in tultip fɔ sho ɔ ayd.
tooltip.toggleEnabled()
chenj
Ɔpdet di pozishɔn fɔ wan ɛlimɛnt in tultip.
tooltip.update()
getInstans fɔ di wan dɛn we de
Statik we de alaw yu fɔ gɛt di tultip instans we gɛt fɔ du wit wan DOM ɛlimɛnt
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
getƆKriɛtInstans
Statik we de alaw yu fɔ gɛt di tultip instans we gɛt fɔ du wit wan DOM ɛlimɛnt, ɔ mek wan nyu wan insay kes we i nɔ bin initialize
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
Di tin dɛn we kin apin
Di kayn tin we apin | Tɔk bɔt |
---|---|
show.bs.tooltip |
Dis ivent de faya wantɛm wantɛm we dɛn kɔl di show instans mɛtɔd. |
shown.bs.tooltip |
Dis ivent de faya we dɛn dɔn mek di tultip si di pɔsin we de yuz am (go wet fɔ mek di CSS transishɔn dɛn dɔn). |
hide.bs.tooltip |
Dis ivent de faya wantɛm wantɛm we hide dɛn dɔn kɔl di instans mɛtɔd. |
hidden.bs.tooltip |
Dis ivent de faya we di tultip dɔn dɔn fɔ ayd frɔm di yuza (go wet fɔ CSS transishɔn dɛn fɔ dɔn). |
inserted.bs.tooltip |
Dis ivent de faya afta di show.bs.tooltip ivent we dɛn dɔn ad di tultip tɛmplat to di DOM. |
var myTooltipEl = document.getElementById('myTooltip')
var tooltip = new bootstrap.Tooltip(myTooltipEl)
myTooltipEl.addEventListener('hidden.bs.tooltip', function () {
// do something...
})
tooltip.hide()