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.js
we 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.
- Tultips kin trig tanks to wan elemɛnt insay wan shado DOM.
Di animashɔn ifɛkt fɔ dis kɔmpɔnɛnt de dipen pan di 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-toggle
atribyut:
Ɛ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 messenger 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.
Ɛn wit kɔstɔm HTML we dɛn ad:
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:
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, sɛt di boundary
opshɔn to ɛni ɔda tin pas difɔlt valyu, 'scrollParent'
, lɛk 'window'
:
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.
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"
, ɛn ɔvalayz di pointer-events
on di disabled element.
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=""
.
Notis se fɔ sikyɔriti rizin dɛn nɔ go ebul fɔ gi di sanitize
, sanitizeFn
ɛn whiteList
opshɔn dɛn we yu de yuz data atribyut dɛn.
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: |
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: |
html | boolean we dɛn kɔl | lay | 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. |
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 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 |
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. 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 . |
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
Di ɔtamost wrap ɛlimɛnt fɔ gɛt di |
taytul | 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 |
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.
|
ɔfset | nɔmba | string fɔ di wan dɛn we de | wok | 0. Di wan dɛn we de | Ɔfset fɔ di tultip rilitiv to in target. 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 ɔfset data as in fɔs argumɛnt. Di fɛnshɔn fɔ ritɔn wan ɔbjɛkt wit di sem strɔkchɔ. Di trigεrin εlimεnt DOM node de pas as di sɛkɔn argumɛnt. 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 . |
fɔ mek yu sanitayz | boolean we dɛn kɔl | tru | Enable ɔ disable di sanitayzeshɔn. If dɛn aktiv 'template' ɛn 'title' opshɔn dɛn go sanitayz. |
waytList fɔ di wan dɛn we de | tin | Difɔlt valyu | Objek we gɛt atribyut ɛn tag dɛn we dɛn alaw |
sanitayzFn fɔ du | nul we de na di wɔl | wok | nɔ gɛt wan valyu | 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. |
popperKɔnfig | nul we de na di wɔl | tin | nɔ gɛt wan valyu | Fɔ chenj Bootstrap in difɔlt Popper.js kɔnfigyushɔn, si Popper.js in kɔnfigyushɔn |
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 .
$().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.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('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.tooltip
tin apin). Dɛn kin tek dis as “manual” we de trig di tultip.
.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.tooltip
ivin apin). Dɛn kin tek dis as “manual” we de trig di tultip.
.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 selector
opshɔn ) nɔ kin ebul fɔ pwɛl wan wan pan disɛndant trig ɛlimɛnt dɛn.
.tooltip('enable')
Gi wan elemɛnt in tultip di abiliti fɔ sho. Tultip dɛn de ɛnabul bay difɔlt.
.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.
.tooltip('toggleEnabled')
Toggles di abiliti fɔ wan elemɛnt in tultip fɔ sho ɔ ayd.
.tooltip('update')
Ɔpdet di pozishɔn fɔ wan ɛlimɛnt in tultip.
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 show instans 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 hide dɛ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.tooltip ivent we dɛn dɔn ad di tultip tɛmplat to di DOM. |