Iingcebiso
Amaxwebhu kunye nemizekelo yokongeza iingcebiso zesiko le-Bootstrap ngeCSS kunye neJavaScript usebenzisa i-CSS3 yoopopayi kunye nedatha-bs-impawu zogcino lwesihloko sendawo.
Isishwankathelo
Izinto omawuzazi xa usebenzisa iplagi yesixhobo se-tooltip:
- Iingcebiso zezixhobo zixhomekeke kwiqela lesithathu kwithala leencwadi lePopper ngokubekwa . Kufuneka ubandakanye i -popper.min.js phambi kwe-bootstrap.js okanye usebenzise
bootstrap.bundle.min.js
/bootstrap.bundle.js
equlethe iPopper ukuze izixhobo zokusebenza zisebenze! - Iingcebiso zezixhobo zingenile ngenxa yezizathu zokusebenza, ke kufuneka uziqalise ngokwakho .
- Iingcebiso zezixhobo ezinezihloko ezibude buziro aziboniswa.
- Cacisa
container: 'body'
ukunqanda unikezelo lweengxaki kumacandelo antsokothileyo (njengamaqela ethu egalelo, amaqela amaqhosha, njl.njl). - Iingcebiso zokuqalisa kwizinto ezifihlakeleyo aziyi kusebenza.
- Iingcebiso zesixhobo
.disabled
okanyedisabled
izakhi kufuneka zivuswe kumbandela wokusonga. - Xa iqaliswa ukusuka kwiihyperlink ezithatha imigca emininzi, iincam zesixhobo ziya kubekwa embindini. Sebenzisa
white-space: nowrap;
kwi yakho<a>
ukunqanda lo kuziphatha. - Iingcebiso mazifihlwe phambi kokuba izinto ezihambelanayo nazo zisuswe kwiDOM.
- Iingcebiso zesixhobo zinokuvuswa enkosi kwinto engaphakathi kwesithunzi se-DOM.
prefers-reduced-motion
kumbuzo wemidiya. Jonga icandelo
leentshukumo ezincitshisiweyo kuxwebhu lwethu lofikelelo .
Unayo yonke loo nto? Kulungile, makhe sibone ukuba basebenza njani ngemizekelo ethile.
Umzekelo: Vumela iingcebiso zesixhobo kuyo yonke indawo
Enye indlela yokuqalisa zonke iingcebiso zesixhobo kwiphepha inokuba kukukhetha ngophawu lwazo data-bs-toggle
:
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
Imizekelo
Hambisa ngaphezulu kwezi linki zingezantsi ukuze ubone iingcebiso zesixhobo:
Isiqendu sesibambi-ndawo sokubonisa amakhonkco angaphakathi ngengcebiso yesixhobo. Oku kukugcwalisa nje, akukho mbulali. Umxholo obekwe apha ukulinganisa ubukho bombhalo wokwenyani . Kwaye konke oko ukukunika umbono wendlela izixhobo zokusebenza ezinokuthi zijongeke ngayo xa zisetyenziswa kwiimeko zokwenyani zehlabathi. Ke ngethemba ukuba ngoku sele ubonile ukuba ezi ngcebiso zesixhobo kwiikhonkco zinokusebenza njani, nje ukuba uzisebenzise kwindawo yakho okanye kwiprojekthi.
Hambisa phezu kwamaqhosha angezantsi ukuze ubone izalathiso zezixhobo ezine: phezulu, ekunene, ezantsi, nasekhohlo. Izalathiso ziboniswa xa usebenzisa i-Bootstrap kwi-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>
Kwaye nge-HTML yesiko elongeziweyo:
<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>
Nge-SVG:
Sass
Izinto eziguquguqukayo
$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;
Ukusetyenziswa
Isixhobo se-plugin se-tooltip sivelisa umxholo kunye ne-markup kwimfuno, kwaye ngokungagqibekanga iindawo zeengcebiso zesixhobo emva kwento yazo yokuqalisa.
Qalisa ingcebiso yesixhobo ngeJavaScript:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, options)
Ukuphuphuma auto
kwayescroll
Indawo yengcebiso yesixhobo izama ukuzitshintsha ngokuzenzekelayo xa isikhongozeli somzali sinaso okanye overflow: auto
sisithanda overflow: scroll
, .table-responsive
kodwa sigcina indawo ebekuyo yokuqala. Ukusombulula oku, cwangcisa boundary
ukhetho (lomlungisi we-flip usebenzisa popperConfig
ukhetho) kuyo nayiphi na iSiqalelo se-HTML ukukhuphela ngaphezulu ixabiso elingagqibekanga, 'clippingParents'
elinje document.body
:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, {
boundary: document.body // or document.querySelector('#boundary')
})
IMarkup
Uphawu olufunekayo lwencam yesixhobo luphawu kuphela data
kwaye title
kwisiqalelo se-HTML unqwenela ukuba nencam yesixhobo. Uphawu oluveliswayo lwencam yesixhobo lulula, nangona lufuna indawo (ngokungagqibekanga, top
lumiselwe yiplagi).
Ukwenza iingcebiso zesixhobo zisebenzele ikhibhodi kunye nabasebenzisi betekhnoloji abancedisayo
Kufuneka wongeze kuphela iingcebiso zesixhobo kwizinto ze-HTML ngokwesiko zekhibhodi-ejolise kwaye isebenze (ezifana namakhonkco okanye ulawulo lwefom). Nangona izinto ze-HTML ezingenamkhethe (ezinje nge- <span>
s) zinokwenziwa ziqwalaselwe ngokongeza tabindex="0"
uphawu, oku kuyakongeza ukumisa okunokucaphukisa kunye nokubhidanisa ithebhu kwizinto ezingasebenzisaniyo kubasebenzisi bebhodi yezitshixo, kwaye uninzi lwetekhnoloji encedisayo ngoku ayazisi inqaku lesixhobo kule meko. Ukongeza, ungathembeli kuphela hover
njengesixhobo sesixhobo sakho, njengoko oku kuya kwenza ukuba izixhobo zakho zesixhobo zingenzeki ukuqalisa kubasebenzisi bebhodi yezitshixo.
<!-- 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>
Izinto ezikhubazekileyo
Izinto disabled
ezinophawu azisebenzi, nto leyo ethetha ukuba abasebenzisi abanakugxila, bashukume, okanye bacofe ukuze baqalise ingcebiso yesixhobo (okanye ipopover). Njengomsebenzi owenziweyo, uya kufuna ukuqalisa inqaku lesixhobo ukusuka kwisonga <div>
okanye <span>
, eyenziwe ngokufanelekileyo ikhibhodi-ijolise ekusebenziseni 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>
Iinketho
Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-bs-
, njengakwi data-bs-animation=""
. Qinisekisa ukuba utshintsha uhlobo lwetyala legama lokukhetha ukusuka kwikamela ukuya kwi-kebab-case xa udlula iinketho ngeempawu zedatha. Umzekelo, endaweni yokusebenzisa data-bs-customClass="beautifier"
, sebenzisa data-bs-custom-class="beautifier"
.
sanitize
,
sanitizeFn
, kunye
allowList
neenketho azikwazi kunikezelwa kusetyenziswa iimpawu zedata.
Igama | Uhlobo | Ukuhlala kukho | Inkcazo |
---|---|---|---|
animation |
boolean | true |
Faka inguqu ye-CSS fade kwi-tooltip |
container |
umtya | into | bubuxoki | false |
Ihlomela incam yesixhobo kwinto ethile. Umzekelo: |
delay |
inombolo | into | 0 |
Ukulibazisa ukubonisa kunye nokufihla isixhobo sesixhobo (ms) - akusebenzi kuhlobo lwesixhobo sokuxhobisa Ukuba inani linikiwe, ukulibaziseka kufakwa kuzo zombini ezifihla/umboniso Ulwakhiwo lwento yile: |
html |
boolean | false |
Vumela i-HTML kwincam yesixhobo. Ukuba yinyaniso, iithegi ze-HTML kwincam yesixhobo Sebenzisa umbhalo ukuba unexhala malunga nohlaselo lwe-XSS. |
placement |
umtya | umsebenzi | 'top' |
Uyibeka njani incam yesixhobo - auto | phezulu | emazantsi | ekhohlo | kunene. Xa umsebenzi usetyenziswa ukumisela ukubekwa, ubizwa ngokuba nencam yesixhobo ye-DOM njengengxoxo yayo yokuqala kunye nesiqalo se-DOM node njengesibini sayo. Umxholo |
selector |
umtya | bubuxoki | false |
Ukuba umkhethi unikiwe, izixhobo zesixhobo ziya kunikezelwa kwiithagethi ezichaziweyo. Ngokwesiqhelo, oku kusetyenziselwa ukusebenzisa iingcebiso zesixhobo kwizinto ezongeziweyo zeDOM ( jQuery.on inkxaso). Bona oku kunye nomzekelo ofundisayo . |
template |
umtya | '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' |
Isiseko se-HTML esinokusetyenziswa xa usenza ingcebiso yesixhobo. Isixhobo se-tooltip
Isiqalelo sokusonga sangaphandle kufuneka sibe |
title |
umtya | into | umsebenzi | '' |
Ixabiso lesihloko esihlala sihleli ukuba Ukuba umsebenzi unikiwe, uya kubizwa kunye |
trigger |
umtya | 'hover focus' |
Ivuswa njani ithiphu yesixhobo - cofa | jonga | gxila | incwadi yesandla. Ungadlula ezininzi izichukumisi; bahlule ngesithuba.
|
fallbackPlacements |
uluhlu | ['top', 'right', 'bottom', 'left'] |
Chaza ukubekelwa umva ngokubonelela ngoluhlu lweendawo ezibekwe kuluhlu (ngolandelelwano olukhethwayo). Ngolwazi oluthe vetshe jonga kumaxwebhu okuziphatha kaPopper |
boundary |
umtya | isiqalelo | 'clippingParents' |
Umda wothintelo lokuphuphumala kwesixhobo (usebenza kuphela kwisilungisi sePopper sokuthintela ukuphuphuma). Ngokungagqibekanga yiyo 'clippingParents' kwaye inokwamkela i-HTMLElement ireferensi (ngeJavaScript kuphela). Ngolwazi oluthe vetshe jonga kuPopper's detectOverflow amaxwebhu . |
customClass |
umtya | umsebenzi | '' |
Yongeza iiklasi kwincam yesixhobo xa ibonisiwe. Qaphela ukuba ezi klasi ziya kongezwa ukongeza kuzo naziphi na iiklasi ezichazwe kwithempleyithi. Ukongeza iiklasi ezininzi, zahlule ngezithuba: Ungaphinda ugqithise umsebenzi ozakubuyisela umtya omnye oqulathe amagama odidi olongezelelweyo. |
sanitize |
boolean | true |
Yenza okanye uvale ucoceko. Ukuba ivuliwe 'template' kwaye 'title' iinketho ziyakuhlanjululwa. Jonga icandelo lesicoci kuxwebhu lwethu lweJavaScript . |
allowList |
into | Ixabiso elimiselweyo | Into equlathe iimpawu ezivumelekileyo kunye neethegi |
sanitizeFn |
null | umsebenzi | null |
Apha ungabonelela ngomsebenzi wakho wokucoca. Oku kunokuba luncedo ukuba ukhetha ukusebenzisa ithala leencwadi elizinikeleyo ukwenza ucoceko. |
offset |
uluhlu | umtya | umsebenzi | [0, 0] |
Iseti yesixhobo esinxulumene noko kujoliswe kuko. Ungadlula umtya kwiimpawu zedatha ezinamaxabiso ahlulwe ngokwekoma afana: Xa umsebenzi usetyenziselwa ukumisela i-offset, ubizwa ngento equlathe ukubeka i-popper, ireferensi, kunye ne-popper i-rects njengengxabano yayo yokuqala. Isiqalo se-DOM node sigqithiselwe njengengxoxo yesibini. Umsebenzi kufuneka ubuyisele uluhlu olunamanani amabini: . Ngolwazi oluthe vetshe jonga kumaxwebhu e-Popper's offset . |
popperConfig |
null | into | umsebenzi | null |
Ukutshintsha uqwalaselo lwePopper lweBootstrap olungagqibekanga, bona uqwalaselo lwePopper . Xa umsebenzi usetyenziswa ukwenza uqwalaselo lwePopper, ibizwa ngento equlathe uqwalaselo lwePopper yeBootstrap engagqibekanga. Ikunceda ukuba usebenzise kwaye udibanise ukungagqibeki kunye noqwalaselo lwakho. Umsebenzi kufuneka ubuyisele into yoqwalaselo yePopper. |
Iimpawu zedatha kwiingcebiso zesixhobo ngasinye
Iinketho zeengcebiso zesixhobo ngasinye zingachazwa ngokusetyenziswa kweempawu zedatha, njengoko kucacisiwe ngasentla.
Ukusebenzisa umsebenzi ngepopperConfig
var tooltip = new bootstrap.Tooltip(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Iindlela
Iindlela zeAsynchronous kunye notshintsho
Zonke iindlela ze-API zi -asynchronous kwaye ziqala utshintsho . Babuyela kumnxeba ngokukhawuleza nje ukuba inguqu iqalisiwe kodwa ingekapheli . Ukongeza, ukufowunelwa kwendlela kwicandelo lenguquko kuya kuhoywa .
bonisa
Ityhila inqaku lesixhobo. Ibuyisela kumnxebi phambi kokuba incam yesixhobo iboniswe (okt phambi kokuba shown.bs.tooltip
isiganeko senzeke). Oku kuthathwa ngokuba "yimanyuwali" yokuqalisa inqaku lesixhobo. Iingcebiso zezixhobo ezinezihloko ezibude buziro aziboniswa.
tooltip.show()
fihla
Ifihla incam yesixhobo. Ibuyisela kumnxeba phambi kokuba incam yesixhobo ifihliwe (okt phambi kokuba hidden.bs.tooltip
isiganeko senzeke). Oku kuthathwa ngokuba "yimanyuwali" yokuqalisa inqaku lesixhobo.
tooltip.hide()
guqula
Itshintshela incam yesixhobo. Ibuyisela kumnxebi phambi kokuba incam yesixhobo iboniswe okanye ifihlwe (okt phambi kokuba isiganeko shown.bs.tooltip
okanye hidden.bs.tooltip
isiganeko senzeke). Oku kuthathwa ngokuba "yimanyuwali" yokuqalisa inqaku lesixhobo.
tooltip.toggle()
lahla
Ifihla kwaye itshabalalise isixhobo sesixhobo (Isusa idatha egciniweyo kwinto yeDOM). Iingcebiso zesixhobo ezisebenzisa unikezelo (ezenziwe ngokusetyenziswa kokhethoselector
) azinakutshatyalaliswa zizodwa kwiziqalelo zokubangela ukuvela .
tooltip.dispose()
yenza
Inika isixhobo sesixhobo sokukwazi ukuboniswa. Iingcebiso zesixhobo zenziwe ngokwendalo.
tooltip.enable()
khubaza
Isusa isakhono sesixhobo sesixhobo sokuboniswa. Ingcebiso yesixhobo iya kuboniswa kuphela ukuba yenziwe yasebenza kwakhona.
tooltip.disable()
toggleEnabled
Iguqula isakhono sesixhobo sesixhobo sokuboniswa okanye ukufihlwa.
tooltip.toggleEnabled()
hlaziya
Ihlaziya indawo yesixhobo sesixhobo.
tooltip.update()
getInstance
Indlela engatshintshiyo ekuvumela ukuba ufumane umzekelo wesixhobo esidityaniswe nesiqalelo seDOM
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
getOrCreateInstance
Indlela engatshintshiyo ekuvumela ukuba ufumane inqaku lesixhobo elinxulunyaniswa nento yeDOM, okanye wenze entsha ukuba ayiqalwanga.
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
Iziganeko
Uhlobo lomsitho | Inkcazo |
---|---|
show.bs.tooltip |
Esi siganeko sivutha ngokukhawuleza xa show kubizwa indlela yomzekelo. |
shown.bs.tooltip |
Esi siganeko sigxothwa xa i-tooltip yenziwe yabonakala kumsebenzisi (iya kulinda iinguqu zeCSS ukuba zigqibe). |
hide.bs.tooltip |
Esi siganeko sigxothwa ngokukhawuleza xa hide indlela yomzekelo ibiziwe. |
hidden.bs.tooltip |
Esi siganeko siyagxothwa xa isixhobo sigqibile ukufihlwa kumsebenzisi (siya kulinda uguqulo lweCSS lugqibe). |
inserted.bs.tooltip |
Esi siganeko sigxothwa emva show.bs.tooltip kwesiganeko xa ithemplate ye-tooltip yongezwa kwi-DOM. |
var myTooltipEl = document.getElementById('myTooltip')
var tooltip = new bootstrap.Tooltip(myTooltipEl)
myTooltipEl.addEventListener('hidden.bs.tooltip', function () {
// do something...
})
tooltip.hide()