Ibikoresho
Inyandiko n'ingero zo kongeramo ibikoresho bya Bootstrap hamwe na CSS na JavaScript ukoresheje CSS3 kuri animasiyo na data-bs-ibiranga kubika umutwe waho.
Incamake
Ibintu ugomba kumenya mugihe ukoresheje plugin ya tooltip:
- Ibikoresho byifashisha isomero ryagatatu rya popper kugirango rihagarare. Ugomba gushyiramo popper.min.js mbere
bootstrap.js
, cyangwa ukoreshe imwebootstrap.bundle.min.js
irimo Popper. - Ibikoresho ni opt-in kubwimpamvu zikorwa, ugomba rero kubitangiza wenyine .
- Ibikoresho bifite imitwe ya zeru-ndende ntibigaragara.
- Kugaragaza
container: 'body'
kugirango wirinde gutanga ibibazo mubice byinshi bigoye (nkitsinda ryacu ryinjiza, amatsinda ya buto, nibindi). - Gukurura ibikoresho byibikoresho byihishe ntabwo bizakora.
- Ibikoresho
.disabled
cyangwadisabled
ibintu bigomba gukururwa kubintu bipfunyika. - Iyo iturutse kuri hyperlinks ikurikirana imirongo myinshi, ibikoresho bizaba hagati. Koresha
white-space: nowrap;
kuri<a>
s kugirango wirinde iyi myitwarire. - Ibikoresho bigomba guhishwa mbere yuko ibintu bihuye bivanwa muri DOM.
- Ibikoresho birashobora gukururwa dukesha ikintu kiri imbere mu gicucu DOM.
Wabonye ibyo byose? Nibyiza, reka turebe uko bakorana ningero zimwe.
prefers-reduced-motion
nibibazo byitangazamakuru. Reba igice
cyagabanijwe cyicyiciro cyibisobanuro byacu .
Ingero
Gushoboza ibikoresho
Nkuko byavuzwe haruguru, ugomba gutangiza ibikoresho mbere yuko bikoreshwa. Inzira imwe yo gutangiza ibikoresho byose kurupapuro byaba ari uguhitamo data-bs-toggle
kubiranga, nka gutya:
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
Ibikoresho ku murongo
Hisha hejuru yibi bikurikira kugirango urebe ibikoresho:
Umwanya wanditse kugirango werekane umurongo uhuza hamwe nibikoresho. Ubu ni uwuzuza gusa, nta mwicanyi. Ibirimo byashyizwe hano gusa kugirango twigane ahari inyandiko nyayo . Kandi ibyo byose kugirango gusa nguhe igitekerezo cyukuntu ibikoresho byakoreshwa mugihe byakoreshejwe mubihe byukuri. Twizere rero ko ubu wabonye uburyo ibi bikoresho byihuza bishobora gukora mubikorwa, iyo ubikoresheje kurubuga rwawe cyangwa umushinga wawe.
<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" data-bs-title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" data-bs-title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" data-bs-title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" data-bs-title="The last tip!">your own</a> site or project.
</p>
title
muri
data-bs-title
HTML yawe. Iyo
title
ikoreshejwe, Popper izayisimbuza mu buryo bwikora hamwe
data-bs-title
nigihe ikintu cyatanzwe.
Ibikoresho byihariye
Wongeyeho muri v5.2.0Urashobora guhitamo isura yibikoresho ukoresheje CSS ihinduka . Twashyizeho urwego rwihariye hamwe data-bs-custom-class="custom-tooltip"
no kugereranya imiterere yacu kandi tuyikoresha kugirango twirengagize CSS ihinduka.
.custom-tooltip {
--bs-tooltip-bg: var(--bs-primary);
}
<button type="button" class="btn btn-secondary"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="This top tooltip is themed via CSS variables.">
Custom tooltip
</button>
Icyerekezo
Hisha hejuru ya buto hepfo kugirango urebe ibyerekezo bine byerekana: hejuru, iburyo, hepfo, n'ibumoso. Icyerekezo kirimo indorerwamo mugihe ukoresheje Bootstrap muri RTL.
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">
Tooltip on top
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="Tooltip on right">
Tooltip on right
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Tooltip on bottom">
Tooltip on bottom
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Tooltip on left">
Tooltip on left
</button>
Hamwe na HTML yihariye yongeyeho:
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" data-bs-title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
Tooltip with HTML
</button>
Hamwe na SVG:
CSS
Ibihinduka
Wongeyeho muri v5.2.0Nkigice cya Bootstrap igenda ihinduka CSS ihindagurika, ibikoresho byifashisha ubu bihindura CSS yaho murwego .tooltip
rwo kuzamura igihe nyacyo. Indangagaciro za CSS zihinduka zashyizweho binyuze kuri Sass, so Sass yihariye iracyashyigikiwe, nayo.
--#{$prefix}tooltip-zindex: #{$zindex-tooltip};
--#{$prefix}tooltip-max-width: #{$tooltip-max-width};
--#{$prefix}tooltip-padding-x: #{$tooltip-padding-x};
--#{$prefix}tooltip-padding-y: #{$tooltip-padding-y};
--#{$prefix}tooltip-margin: #{$tooltip-margin};
@include rfs($tooltip-font-size, --#{$prefix}tooltip-font-size);
--#{$prefix}tooltip-color: #{$tooltip-color};
--#{$prefix}tooltip-bg: #{$tooltip-bg};
--#{$prefix}tooltip-border-radius: #{$tooltip-border-radius};
--#{$prefix}tooltip-opacity: #{$tooltip-opacity};
--#{$prefix}tooltip-arrow-width: #{$tooltip-arrow-width};
--#{$prefix}tooltip-arrow-height: #{$tooltip-arrow-height};
Ibihinduka bya Sass
$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: null; // TODO: remove this in v6
$tooltip-arrow-width: .8rem;
$tooltip-arrow-height: .4rem;
// fusv-disable
$tooltip-arrow-color: null; // Deprecated in Bootstrap 5.2.0 for CSS variables
// fusv-enable
Ikoreshwa
Ibikoresho bya plugin bitanga ibikubiyemo nibiranga kubisabwa, kandi kubisanzwe byerekana ibikoresho nyuma yibintu byabo.
Koresha ibikoresho ukoresheje JavaScript:
const exampleEl = document.getElementById('example')
const tooltip = new bootstrap.Tooltip(exampleEl, options)
Kurenga auto
kandiscroll
Umwanya wibikoresho ugerageza guhita uhinduka mugihe ikintu cyababyeyi gifite overflow: auto
cyangwa overflow: scroll
nkicyacu .table-responsive
, ariko iracyakomeza imyanya yumwimerere. Kugira ngo iki kibazo gikemuke, shiraho boundary
amahitamo (kuri flip modifier ukoresheje popperConfig
amahitamo) kuri HTMLElement iyariyo yose kugirango urengere agaciro gasanzwe, 'clippingParents'
nka document.body
:
const tooltip = new bootstrap.Tooltip('#example', {
boundary: document.body // or document.querySelector('#boundary')
})
Markup
Ikimenyetso gisabwa kubikoresho ni data
ikiranga gusa no title
kuri element ya HTML wifuza kugira igikoresho. Ikimenyetso cyakozwe mubikoresho byoroshye biroroshye, nubwo bisaba umwanya (kubisanzwe, byashyizweho top
na plugin).
Gukora ibikoresho bikora kuri clavier hamwe nabafasha gukoresha ikoranabuhanga
Ugomba kongeramo gusa ibikoresho byibikoresho bya HTML bisanzwe bisanzwe bya clavier-byibanda kandi bigakorana (nkumuhuza cyangwa kugenzura imiterere). Nubwo ibintu bya HTML uko bishakiye (nka <span>
s) bishobora gukorwa byibandwaho mukongeramo tabindex="0"
ikiranga, ibi bizongeramo ibishoboka birakaze kandi bitesha umutwe tab ihagarara kubintu bidakorana kubakoresha clavier, kandi tekinoroji ifasha muri iki gihe ntabwo itangaza ibikoresho muri ibi bihe. Ikigeretse kuri ibyo, ntukishingikirize gusa hover
nkigitera ibikoresho byawe, kuko ibi bizatuma ibikoresho byawe bidashoboka gukurura abakoresha clavier.
<!-- HTML to write -->
<a href="#" data-bs-toggle="tooltip" data-bs-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>
Ibintu byahagaritswe
Ibintu bifite disabled
ikiranga ntabwo bikorana, bivuze ko abakoresha badashobora kwibanda, kugendagenda, cyangwa kubikanda kugirango batere igikoresho (cyangwa popover). Nkumurimo wakazi, uzashaka gukurura ibikoresho biva mubipfunyika <div>
cyangwa <span>
, nibyiza byakozwe na clavier-yibanze ukoresheje tabindex="0"
.
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-title="Disabled tooltip">
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>
Amahitamo
Nkuko amahitamo ashobora kunyuzwa kumurongo wamakuru cyangwa JavaScript, urashobora kongeramo izina ryamahitamo data-bs-
, nkuko biri data-bs-animation="{value}"
. Witondere guhindura ubwoko bwurubanza rwamahitamo kuva " ingamiya " kuri " kebab-urubanza " mugihe utambutsa amahitamo ukoresheje ibiranga amakuru. Kurugero, koresha data-bs-custom-class="beautifier"
aho data-bs-customClass="beautifier"
.
Nko muri Bootstrap 5.2.0, ibice byose bishyigikira igeragezwa ryibitse ryamakuru data-bs-config
rishobora kubamo ibice byoroshye nkibikoresho bya JSON. Mugihe ikintu gifite data-bs-config='{"delay":0, "title":123}'
nibiranga data-bs-title="456"
, agaciro kanyuma title
kazaba 456
kandi amakuru yihariye aranga agaciro katanzwe kuri data-bs-config
. Mubyongeyeho, amakuru ariho aranga arashobora kubika JSON indangagaciro nka data-bs-delay='{"show":0,"hide":150}'
.
sanitize
,,
sanitizeFn
hamwe
allowList
namahitamo ntashobora gutangwa ukoresheje ibiranga amakuru.
Izina | Andika | Mburabuzi | Ibisobanuro |
---|---|---|---|
allowList |
ikintu | Agaciro gasanzwe | Ikintu kirimo ibiranga byemewe na tagi. |
animation |
boolean | true |
Koresha CSS igenda ihinduka kubikoresho. |
boundary |
umugozi, ikintu | 'clippingParents' |
Kurenga imipaka imipaka yibikoresho (ikoreshwa gusa kuri popper yo gukumiraOverflow modifier). Mburabuzi, ni 'clippingParents' kandi irashobora kwakira HTMLElement yerekanwe (binyuze kuri JavaScript gusa). Kubindi bisobanuro reba popper's detectOverflow docs . |
container |
umugozi, ikintu, ibinyoma | false |
Ongeraho ibikoresho byibikoresho runaka. Urugero : container: 'body' . Ihitamo ni ingirakamaro cyane cyane kuburyo rigufasha gushyira ibikoresho byifashishwa mugutembera kwinyandiko hafi yikintu gikurura - bizarinda igikoresho cyo kureremba kure yikintu gikurura mugihe idirishya rinini. |
customClass |
umugozi, imikorere | '' |
Ongeraho amasomo kubikoresho iyo byerekanwe. Menya ko aya masomo azongerwaho hiyongereyeho ibyiciro byose byerekanwe mubishusho. Ongeraho ibyiciro byinshi, ubitandukanye numwanya : 'class-1 class-2' . Urashobora kandi gutambutsa imikorere igomba gusubiza umurongo umwe urimo amazina yinyongera yinyongera. |
delay |
umubare, ikintu | 0 |
Gutinda kwerekana no guhisha ibikoresho (ms) - ntibikoreshwa muburyo bwintoki. Niba umubare watanzwe, gutinda gukoreshwa byombi guhisha / kwerekana. Imiterere yibintu ni : delay: { "show": 500, "hide": 100 } . |
fallbackPlacements |
array | ['top', 'right', 'bottom', 'left'] |
Sobanura ibyasubiwemo mugutanga urutonde rwibisobanuro (murwego rwo guhitamo). Kubindi bisobanuro reba imyitwarire ya Popper . |
html |
boolean | false |
Emerera HTML mubikoresho. Niba ari ukuri, ibirango bya HTML mubikoresho byerekana title bizerekanwa mubikoresho. Niba ari ibinyoma, innerText umutungo uzakoreshwa mugushyiramo ibiri muri DOM. Koresha inyandiko niba uhangayikishijwe n'ibitero bya XSS. |
offset |
umurongo, umugozi, imikorere | [0, 0] |
Offset ya tooltip ugereranije nintego yayo. Urashobora gutambutsa umurongo muri data ibiranga hamwe na koma yatandukanijwe indangagaciro nka : data-bs-offset="10,20" . Iyo imikorere ikoreshwa mukumenya offset, yitwa hamwe nikintu kirimo icyerekezo cya popper, icyerekezo, hamwe na popper ikosora nkibitekerezo byayo byambere. Ikintu gikurura DOM node yatambutse nkimpaka ya kabiri. Igikorwa kigomba gusubiza umurongo hamwe nimibare ibiri: kunyerera , intera . Kubindi bisobanuro reba kuri popper ya offset . |
placement |
umugozi, imikorere | 'top' |
Nigute washyira ibikoresho: auto, hejuru, hepfo, ibumoso, iburyo. Iyo auto bisobanuwe neza, bizahindura icyerekezo cyibikoresho. Iyo imikorere ikoreshwa mukumenya aho ishyirwa, byitwa hamwe na tooltip DOM node nkibisobanuro byayo byambere hamwe na elementing DOM node nkibya kabiri. Imirongo this yashizwe kumurongo wibikoresho. |
popperConfig |
ubusa, ikintu, imikorere | null |
Guhindura Bootstrap isanzwe ya Popper config, reba iboneza rya Popper . Iyo imikorere ikoreshwa mugukora iboneza rya popper, byitwa hamwe nikintu kirimo Bootstrap isanzwe ya Popper. Iragufasha gukoresha no guhuza ibisanzwe hamwe nuburyo bwawe bwite. Imikorere igomba gusubiza ibintu byabugenewe kuri Popper. |
sanitize |
boolean | true |
Gushoboza cyangwa guhagarika isuku. Nibikora 'template' , 'content' kandi 'title' amahitamo azagira isuku. |
sanitizeFn |
ubusa, imikorere | null |
Hano urashobora gutanga imikorere yawe yisuku. Ibi birashobora kuba ingirakamaro niba uhisemo gukoresha isomero ryabigenewe kugirango ukore isuku. |
selector |
umugozi, ibinyoma | false |
Niba uwatoranije atanzwe, ibikoresho byibikoresho bizahabwa intego zerekanwe. Mu myitozo, ibi bikoreshwa mugukoresha ibikoresho byongeweho imbaraga za DOM ( jQuery.on inkunga). Reba iki kibazo nurugero rwamakuru . |
template |
umugozi | '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' |
Shingiro HTML yo gukoresha mugihe uremye ibikoresho. Ibikoresho bya title bikoresho bizaterwa muri .tooltip-inner . .tooltip-arrow Byahindutse umwambi wibikoresho. Ikintu cyo gupfunyika hanze kigomba kugira urwego .tooltip na role="tooltip" . |
title |
umugozi, ikintu, imikorere | '' |
Mburabuzi Umutwe Agaciro niba title Ikiranga kidahari. Niba imikorere yatanzwe, izahamagarwa hamwe this nibisobanuro byayo kuri element popover ifatanye. |
trigger |
umugozi | 'hover focus' |
Uburyo ibikoresho byifashishwa: kanda, hejuru, kwibanda, imfashanyigisho. Urashobora gutsinda imbarutso nyinshi; kubatandukanya n'umwanya. 'manual' yerekana ko igikoresho kizaterwa na porogaramu binyuze muri .tooltip('show') , .tooltip('hide') nuburyo .tooltip('toggle') ; agaciro ntigashobora guhuzwa nizindi mbarutso. 'hover' ku giti cyayo bizavamo ibikoresho bidashobora gukururwa hifashishijwe clavier, kandi bigomba gukoreshwa gusa niba ubundi buryo bwo gutanga amakuru amwe kubakoresha clavier ahari. |
Ibiranga amakuru kubikoresho byihariye
Amahitamo kubikoresho bya buri muntu arashobora gutondekwa muburyo bwo gukoresha ibiranga amakuru, nkuko byasobanuwe haruguru.
Gukoresha imikorere hamwepopperConfig
const tooltip = new bootstrap.Tooltip(element, {
popperConfig(defaultBsPopperConfig) {
// const newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Uburyo
Uburyo butajegajega ninzibacyuho
Inzira zose za API ntizihuza kandi zitangira inzibacyuho . Basubira kumuhamagara mugihe inzibacyuho itangiye ariko itararangira . Mubyongeyeho, uburyo bwo guhamagarira ibice byinzibacyuho bizirengagizwa .
Uburyo | Ibisobanuro |
---|---|
disable |
Kuraho ubushobozi bwibikoresho byerekanwa. Igikoresho kizashobora gusa kwerekanwa niba cyongeye gukora. |
dispose |
Hisha kandi isenya igikoresho cyibikoresho (Kuraho amakuru yabitswe kubintu bya DOM). Ibikoresho bifashisha intumwa (zakozwe hakoreshejwe amahitamoselector ) ntibishobora gusenywa kugiti cyawe kubintu bikomokaho . |
enable |
Itanga igikoresho cyibikoresho ubushobozi bwo kwerekanwa. Ibikoresho bifasha byanze bikunze. |
getInstance |
Uburyo buhamye bugufasha kubona urugero rwibikoresho bifitanye isano na DOM, cyangwa gukora bundi bushya mugihe bitatangijwe. |
getOrCreateInstance |
Uburyo buhamye bugufasha kubona urugero rwibikoresho bifitanye isano na DOM, cyangwa gukora bundi bushya mugihe bitatangijwe. |
hide |
Hisha igikoresho cyibikoresho. Garuka kumuhamagara mbere yigikoresho cyihishe mubyukuri (nukuvuga mbere yuko hidden.bs.tooltip ibyabaye biba). Ibi bifatwa nk "intoki" itera ibikoresho. |
setContent |
Itanga uburyo bwo guhindura ibikubiyemo ibikoresho nyuma yo gutangira. |
show |
Yerekana igikoresho cyibikoresho. Garuka kumuhamagara mbere yuko ibikoresho byerekanwe (ni ukuvuga mbere yuko shown.bs.tooltip ibyabaye biba). Ibi bifatwa nk "intoki" itera ibikoresho. Ibikoresho bifite imitwe ya zeru ntigaragara. |
toggle |
Kuzuza ibikoresho by'ibikoresho. Garuka kumuhamagara mbere yuko ibikoresho byerekanwe cyangwa byihishe (ni ukuvuga mbere yuko ibyabaye shown.bs.tooltip cyangwa hidden.bs.tooltip ibyabaye bibaho). Ibi bifatwa nk "intoki" itera ibikoresho. |
toggleEnabled |
Kuzamura ubushobozi bwibikoresho byerekanwa cyangwa byihishe. |
update |
Kuvugurura umwanya wibikoresho bya element. |
const tooltip = bootstrap.Tooltip.getInstance('#example') // Returns a Bootstrap tooltip instance
// setContent example
tooltip.setContent({ '.tooltip-inner': 'another title' })
setContent
bwemera
object
impaka, aho buri mutungo-urufunguzo numutoranya wemewe
string
mubishushanyo mbonera, kandi buri mutungo-agaciro ushobora kuba
string
|
element
|
function
|
null
Ibyabaye
Icyabaye | Ibisobanuro |
---|---|
hide.bs.tooltip |
Ibi birori birahita bisohoka mugihe uburyo hide bwurugero bwahamagawe. |
hidden.bs.tooltip |
Ibirori birukanwa mugihe popover yarangije guhishwa uyikoresha (azategereza ko inzibacyuho ya CSS irangira). |
inserted.bs.tooltip |
Ibirori birukanwa nyuma show.bs.tooltip yibyabaye mugihe ibikoresho byifashishijwe byongewe kuri DOM. |
show.bs.tooltip |
Ibirori birasa ako kanya mugihe show urugero rwitwa. |
shown.bs.tooltip |
Ibirori birukanwa mugihe popover yakozwe igaragara kubakoresha (izategereza ko inzibacyuho ya CSS irangira). |
const myTooltipEl = document.getElementById('myTooltip')
const tooltip = bootstrap.Tooltip.getOrCreateInstance(myTooltipEl)
myTooltipEl.addEventListener('hidden.bs.tooltip', () => {
// do something...
})
tooltip.hide()