Source

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-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.js fɔ pozishɔn. Yu fɔ put popper.min.js bifo bootstrap.js ɔ yuz bootstrap.bundle.min.js/ bootstrap.bundle.jswe gɛt Popper.js fɔ mek tultip dɛn wok!
  • If yu de bil wi JavaSkript frɔm sɔs, i nid fɔutil.js .
  • 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.

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-toggleatribyut:

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})

Ɛgzampul dɛn

Hova oba di link dɛn we de dɔŋ fɔ si tultip dɛn:

Tayt pant neks levul keffiyeh yu probabli no don yehri boht dem. Foto booth biad raw denim letterpress vegan mesenja bag stumptown. Fam-to-tebul seitan, mcsweeney in fixie sataynabul quinoa 8-bit american apɛl gɛt wan tɛri richardson vaynil chambray. Beard stumptown, kardigan banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, fo loko mcsweeney in klin vegan chambray. A rili ironic artisan wetin keytar , scenester fam-to-tebul banksy Austin twita handle frigan cred raw denim singl-orijin kɔfi vayral.

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.

<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
  Tooltip on top
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="right" title="Tooltip on right">
  Tooltip on right
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">
  Tooltip on bottom
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-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-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
  Tooltip with HTML
</button>

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:

$('#example').tooltip(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: scrolllɛk wi .table-responsive, bɔt stil de kip di ɔrijinal plesmɛnt in pozishɔn. Fɔ sɔlv, sɛt di boundaryopshɔn to ɛni ɔda tin pas difɔlt valyu, 'scrollParent', lɛk 'window':

$('#example').tooltip({ boundary: 'window' })

Mak-ap fɔ di tin dɛn we de apin

Di mak we yu nid fɔ wan tultip na jɔs wan dataatribyut ɛn titlena 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, topdi 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. Apat frɔm dat, bɔku pan di ɛp tɛknɔlɔji dɛn naw nɔ de anɔys di tultip na dis sityueshɔn.

Apat frɔm dat, nɔ jɔs abop pan hoveras 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-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="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 disabledatribyut 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", ɛn ɔvalayz di pointer-eventson di disabled element.

<span class="d-inline-block" tabindex="0" data-toggle="tooltip" title="Disabled tooltip">
  <button class="btn btn-primary" style="pointer-events: none;" 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-, lɛk insay data-animation="".

Nem Kayn Balans Tɔk bɔt
animashɔn fɔ di pikchɔ dɛn boolean we dɛn kɔl tru Aplay wan CSS fade transishɔn to di tultip
kɔntena we dɛn kin put insay string fɔ di wan dɛn we de | elemɛnt | lay lay

Apɛnd di tultip to wan patikyula ɛlimɛnt. Fɔ ɛgzampul: container: 'body'. Dis opshɔn rili yusful bikɔs i de alaw yu fɔ posishun di tultip na di flɔ na di dɔkyumɛnt nia di trig ɛlimɛnt - we go mek di tultip nɔ flɔt away frɔm di trig ɛlimɛnt we yu de risayz di winda.

westɛm nɔmba | tin 0. Di wan dɛn we de

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:delay: { "show": 500, "hide": 100 }

html boolean we dɛn kɔl lay

Alaw HTML na di tultip.

If na tru, HTML tag dɛn na di tultip’s titlego rɛnd na di tultip. If na lay, textdɛn go yuz jQuery in we fɔ put kɔntinyu insay di DOM.

Yuz tɛks if yu de wɔri bɔt XSS atak dɛn.

ples fɔ put am string fɔ di wan dɛn we de | wok 'ɔp'

Aw fɔ posishun di tultip - ɔto | top | dɔŋ ya | lɛft | rayt.
We autodɛn spɛsifa am, i go dinamik wan rioriɛnt di tultip.

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 thiskɔntɛks de sɛt to di tultip instans.

sɛlɛktɔ string fɔ di wan dɛn we de | lay lay 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. Insay prɔsis, dɛn kin yuz dis fɔ mek dinamik HTML kɔntinyu fɔ gɛt popovers we dɛn ad. Si dis ɛn wan ɛgzampul we gɛt bɔku tin dɛn fɔ no bɔt .
tɛmplat fɔ di wan dɛn we de rop '<div class="tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>'

Base HTML fɔ yuz we yu de mek di tultip.

Di tultip dɛn titlego injɛkt insay di .tooltip-inner.

.arrowgo bi di tultip in aro.

Di ɔtamost wrap ɛlimɛnt fɔ gɛt di .tooltipklas ɛn role="tooltip".

taytul string fɔ di wan dɛn we de | elemɛnt | wok '' .

Difɔlt taytul valyu if titleatribyut nɔ de.

If dɛn gi wan fɛnshɔn, dɛn go kɔl am wit in thisrɛfrɛns sɛt to di ɛlimɛnt we di tultip ataya to.

stat rop 'hova fɔs'.

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.

'manual'sho se di tultip go trig programmatik wan via di .tooltip('show'), .tooltip('hide')ɛn .tooltip('toggle')di we dɛn; dis valyu nɔ kin kam togɛda wit ɛni ɔda trig.

'hover'pan insɛf go mek dɛn gɛt tultip dɛn we dɛn nɔ go ebul fɔ trig bay di kibɔd, ɛn dɛn fɔ jɔs yuz am if ɔda we dɛn de fɔ gi di sem infɔmeshɔn to di wan dɛn we de yuz di kibɔd de.

ɔfset nɔmba | rop 0. Di wan dɛn we de Ɔfset fɔ di tultip rilitiv to in target. Fɔ no mɔ, luk na Popper.js in ɔfset dɔkyumɛnt dɛn .
fallbackPlesmɛnt fɔ put string fɔ di wan dɛn we de | arenjmɛnt fɔ di wan dɛn we de 'tɔn oba' Alaw fɔ spɛsifa us pozishɔn Popa go yuz pan fɔl bak. Fɔ no mɔ, luk na Popper.js in bihayvya dɔkyumɛnt dɛn
bɔda string fɔ di wan dɛn we de | tin 'skrolParent'. Ovaflɔ kɔnstrakshɔn bɔda fɔ di tultip. Aksept di valyu dɛn fɔ 'viewport', 'window', 'scrollParent', ɔ wan HTMLElement rɛfrɛns (JavaSkript nɔmɔ). Fɔ no mɔ, luk na Popper.js in preventOverflow docs .

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.

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 .

Si wi JavaSkript dɔkyumentri fɔ no mɔ.

$().tooltip(options)

Ataya wan tultip handla to wan ɛlimɛnt kɔlɛkshɔn.

.tooltip('show')

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.tooltiptin 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.

$('#element').tooltip('show')

.tooltip('hide')

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.tooltiptin apin). Dɛn kin tek dis as “manual” we de trig di tultip.

$('#element').tooltip('hide')

.tooltip('toggle')

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.tooltipivin apin). Dɛn kin tek dis as “manual” we de trig di tultip.

$('#element').tooltip('toggle')

.tooltip('dispose')

Ayd ɛn pwɛl wan ɛlimɛnt in tultip. Tultip dɛn we de yuz delegɛshɔn (we dɛn mek yuz di selectoropshɔn ) nɔ kin ebul fɔ pwɛl wan wan pan disɛndant trig ɛlimɛnt dɛn.

$('#element').tooltip('dispose')

.tooltip('enable')

Gi wan elemɛnt in tultip di abiliti fɔ sho. Tultip dɛn de ɛnabul bay difɔlt.

$('#element').tooltip('enable')

.tooltip('disable')

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.

$('#element').tooltip('disable')

.tooltip('toggleEnabled')

Toggles di abiliti fɔ wan elemɛnt in tultip fɔ sho ɔ ayd.

$('#element').tooltip('toggleEnabled')

.tooltip('update')

Ɔpdet di pozishɔn fɔ wan ɛlimɛnt in tultip.

$('#element').tooltip('update')

Di tin dɛn we kin apin

Di kayn tin we apin Tɔk bɔt
sho.bs.tultip fɔ sho Dis ivent de faya wantɛm wantɛm we dɛn kɔl di showinstans mɛtɔd.
we dɛn sho.bs.tultip 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).
ayd.bs.tultip fɔ di wan dɛn we de Dis ivent de faya wantɛm wantɛm we hidedɛn dɔn kɔl di instans mɛtɔd.
di wan dɛn we de ayd.bs.tultip 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).
dɛn dɔn put insay.bs.tultip Dis ivent de faya afta di show.bs.tooltipivent we dɛn dɔn ad di tultip tɛmplat to di DOM.
$('#myTooltip').on('hidden.bs.tooltip', function () {
  // do something…
})