Lisebelisoa
Litokomane le mehlala ea ho eketsa lisebelisoa tsa lisebelisoa tsa Bootstrap ka CSS le JavaScript u sebelisa CSS3 bakeng sa lipopae le lintlha-bs-ts'ebetso bakeng sa polokelo ea lihlooho tsa lehae.
Kakaretso
Lintho tseo u lokelang ho li tseba ha u sebelisa plugin ea tooltip:
- Litlhahiso li itšetlehile ka laeborari ea batho ba boraro ea Popper bakeng sa maemo. U tlameha ho kenyelletsa popper.min.js pele ho
bootstrap.js
, kapa u sebelise ebootstrap.bundle.min.js
nang le Popper. - Litlhahiso ke tsa ho kena ka mabaka a ts'ebetso, kahoo u tlameha ho li qala ka bouena .
- Lisebelisoa tse nang le lihlooho tsa bolelele ba zero ha li hlahisoe.
- Hlakisa
container: 'body'
ho qoba ho fana ka mathata ka likarolo tse rarahaneng (joalo ka lihlopha tsa rona tsa ho kenya, lihlopha tsa likonopo, joalo-joalo). - Ho kenya lisebelisoa ho lisebelisoa tse patiloeng ho ke ke ha sebetsa.
- Lisebelisoa tsa lisebelisoa
.disabled
kapadisabled
likarolo li tlameha ho hlahisoa holim'a karolo ea wrapper. - Ha e hlahisoa ho tsoa ho li-hyperlink tse nang le mela e mengata, lisebelisoa tsa lisebelisoa li tla ba teng. Sebelisa
white-space: nowrap;
ho hao<a>
ho qoba boitšoaro bona. - Lisebelisoa li tlameha ho patoa pele likarolo tsa tsona tse tsamaellanang li tlosoa ho DOM.
- Lisebelisoa li ka hlahisoa ka lebaka la ntho e ka hare ho moriti oa DOM.
O nale tseo tsohle? E kholo, a re boneng hore na ba sebetsa joang ka mehlala e meng.
prefers-reduced-motion
potso ea media. Sheba karolo e
fokolitsoeng ea motsamao oa litokomane tsa phihlello ea rona .
Mehlala
Lumella lisebelisoa tsa lisebelisoa
Joalokaha ho boletsoe ka holimo, u tlameha ho qala lisebelisoa tsa lisebelisoa pele li ka sebelisoa. Tsela e 'ngoe ea ho qala lisebelisoa tsohle tse leqepheng e tla ba ho li khetha ka data-bs-toggle
tšobotsi ea tsona, joalo ka:
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
Lisebelisoa tsa li-link
Tsamaea holim'a lihokelo tse ka tlase ho bona lintlha tsa lisebelisoa:
Mongolo oa sebapali ho bonts'a lihokelo tsa inline tse nang le lisebelisoa tsa lisebelisoa. Hona joale ke ho tlatsa feela, ha ho 'molai. Litaba tse behiloeng mona ho etsisa boteng ba mongolo oa 'nete . 'Me sena sohle ke ho u fa leseli la hore na lithulusi li tla shebahala joang ha li sebelisoa maemong a nnete a lefats'e. Kahoo ka tšepo u se u bone hore na lisebelisoa tsena tsa lihokelo li ka sebetsa joang ha u se u li sebelisa sebakeng sa hau sa marang- rang kapa morerong oa hau.
<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
kapa
data-bs-title
ho HTML ea hau. Ha
title
e sebelisoa, Popper e tla e nkela sebaka ka bo eona
data-bs-title
ha elemente e etsoa.
Lisebelisoa tse ikhethileng
E kentsoe ho v5.2.0U ka etsa hore ponahalo ea lithulusi u sebelise mefuta e fapaneng ea CSS . Re theha sehlopha sa tloaelo se nang le data-bs-custom-class="custom-tooltip"
ho lekanya ponahalo ea rona ea tloaelo le ho e sebelisa ho fetisa phapang ea lehae ea CSS.
.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>
Litsela
Tsamaea holim'a likonopo tse ka tlase ho bona litsela tse 'ne tsa lisebelisoa: holimo, ho le letona, tlase le le letšehali. Litaelo li bonts'oa ha u sebelisa Bootstrap ho 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>
'Me ka HTML e tloaelehileng e ekelitsoe:
<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>
Ka SVG:
CSS
Lintho tse fapaneng
E kentsoe ho v5.2.0E le karolo ea mokhoa oa ho fetoha oa CSS oa Bootstrap, lisebelisoa tsa lisebelisoa joale li sebelisa mefuta-futa ea CSS ea lehae .tooltip
bakeng sa ho ntlafatsa nako ea sebele. Litekanyetso tsa mefuta-futa ea CSS li behiloe ka Sass, kahoo mokhoa oa Sass o ntse o tšehetsoa, le oona.
--#{$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};
Mefuta e fapaneng ea 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
Tšebeliso
plugin ea tooltip e hlahisa litaba le markup ha ho hlokahala, 'me ka ho sa feleng e beha malebela ka mor'a ntho ea eona ea ho qala.
Qala sesebelisoa ka JavaScript:
const exampleEl = document.getElementById('example')
const tooltip = new bootstrap.Tooltip(exampleEl, options)
Khala auto
lescroll
Sebaka sa Tooltip se leka ho fetoha ha sesebelisoa sa motsoali se rata overflow: auto
kapa se overflow: scroll
rata .table-responsive
, empa se ntse se boloka boemo ba sebaka sa pele. Ho rarolla sena, beha boundary
khetho (bakeng sa mofetoleli oa flip o sebelisa popperConfig
khetho) ho HTMLElement efe kapa efe ho hlakola boleng ba kamehla 'clippingParents'
, joalo ka document.body
:
const tooltip = new bootstrap.Tooltip('#example', {
boundary: document.body // or document.querySelector('#boundary')
})
Markup
Letšoao le hlokahalang bakeng sa sesebelisoa ke data
tšobotsi feela 'me title
ho karolo ea HTML u lakatsa ho ba le sesebelisoa. Thepa e hlahisitsoeng ea sesebelisoa e bonolo, leha e hloka boemo (ka kamehla, e behiloeng top
ke plugin).
Ho etsa hore malebela a lithulusi a sebetse ho keyboard le basebelisi ba theknoloji e thusang
U lokela ho kenya feela malebela a lisebelisoa ho likarolo tsa HTML tseo ka tloaelo li shebaneng le keyboard le ho sebelisana (joalo ka likhokahano kapa litsamaiso tsa foromo). Leha likarolo tsa HTML tse sa reroang (joalo ka <span>
s) li ka tsepamisoa maikutlo ka ho kenyelletsa tabindex="0"
tšobotsi, sena se tla eketsa litopo tse ka bang tsa khopisa le tse ferekanyang linthong tse sa sebelisaneng bakeng sa basebelisi ba keyboard, 'me mahlale a mangata a thusang hajoale ha a phatlalatse sesebelisoa boemong bona. Ho phaella moo, u se ke ua itšetleha feela ka hover
hore e be mohloli oa lisebelisoa tsa hau, kaha sena se tla etsa hore lisebelisoa tsa hau tsa lisebelisoa li se ke tsa khoneha bakeng sa basebelisi ba keyboard.
<!-- 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>
Lintho tse holofetseng
Lintho tse nang le disabled
tšobotsi ha li sebelisane, ho bolelang hore basebelisi ha ba khone ho tsepamisa maikutlo, ho ōka, kapa ho li tobetsa ho kenya lisebelisoa (kapa popover). Joalo ka mokhoa oa ho sebetsa, o tla batla ho qala sesebelisoa ho tsoa ho sephutheloana <div>
kapa <span>
, se etselitsoeng hantle hore se tsepamise mohopolo ho sebelisa 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>
Dikgetho
Kaha likhetho li ka fetisoa ka lintlha tsa data kapa JavaScript, u ka kenyelletsa lebitso la khetho ho data-bs-
, joalo ka data-bs-animation="{value}"
. Etsa bonnete ba hore o fetola mofuta oa nyeoe ea lebitso la khetho ho tloha " camelCase "ho " kebab-case " ha o fetisa likhetho ka litšobotsi tsa data. Ka mohlala, sebelisa data-bs-custom-class="beautifier"
ho e-na le data-bs-customClass="beautifier"
.
Ho tloha ka Bootstrap 5.2.0, likarolo tsohle li ts'ehetsa tlhahlobo ea data e bolokiloeng data-bs-config
e ka bolokang tlhophiso e bonolo ea karolo joalo ka khoele ea JSON. Ha element e na data-bs-config='{"delay":0, "title":123}'
le data-bs-title="456"
litšoaneleho, boleng ba ho qetela title
bo tla ba 456
'me lintlha tse arohaneng tsa data li tla feta boleng bo fanoeng ho data-bs-config
. Ntle le moo, litšoaneleho tse teng tsa data li khona ho boloka boleng ba JSON joalo ka data-bs-delay='{"show":0,"hide":150}'
.
sanitize
,
sanitizeFn
, le
allowList
likhetho li ke ke tsa fanoa ho sebelisoa litšobotsi tsa data.
Lebitso | Mofuta | Ea kamehla | Tlhaloso |
---|---|---|---|
allowList |
ntho | Boleng ba kamehla | Ntho e nang le litšobotsi le li-tag tse lumelletsoeng. |
animation |
boolean | true |
Kenya phetoho ea CSS fade ho tooltip. |
boundary |
khoele, element | 'clippingParents' |
Moeli o thibelang ho phalla ha sesebelisoa (e sebetsa feela ho Popper's preventOverflow modifier). Ka mokhoa o ikhethileng, ke ' 'clippingParents' me e ka amohela tšupiso ea HTMLElement (ka JavaScript feela). Ho fumana lintlha tse ling, sheba ho Popper's detectOverflow docs . |
container |
khoele, element, bohata | false |
E kopanya ntlha ea lisebelisoa ho ntho e itseng. Mohlala container: 'body' :. Khetho ena e na le thuso ka ho khetheha hobane e u lumella ho beha sesebelisoa ho phallo ea tokomane haufi le ntho e qalang - e tla thibela sesebelisoa hore se se ke sa phaphamala ho tloha nthong e qalang nakong ea ho fetola boholo ba fensetere. |
customClass |
khoele, mosebetsi | '' |
Kenya litlelase ntlheng ea lisebelisoa ha e bonts'oa. Hlokomela hore litlelase tsena li tla eketsoa ho kenyelletsa litlelase life kapa life tse boletsoeng template. Ho eketsa lihlopha tse ngata, li arole ka libaka: 'class-1 class-2' . U ka fetisa tšebetso e lokelang ho khutlisa khoele e le 'ngoe e nang le mabitso a sehlopha sa tlatsetso. |
delay |
palo, ntho | 0 |
Tieho ea ho bontša le ho pata ntlha ea lisebelisoa (ms)—ha e sebetse mofuteng oa ho kenya letsoho. Haeba nomoro e fanoe, ho lieha ho sebelisoa ho pata/show ka bobeli. delay: { "show": 500, "hide": 100 } Sebopeho sa ntho ke:. |
fallbackPlacements |
array | ['top', 'right', 'bottom', 'left'] |
Hlalosa lipehelo tsa morao-rao ka ho fana ka lethathamo la libaka tse behiloeng ka tatellano (ho ea ka khetho). Ho fumana lintlha tse ling, sheba ho Popper's behaviour docs . |
html |
boolean | false |
Lumella HTML karolong ea lisebelisoa. Haeba ke 'nete, li-tag tsa HTML tse karolong ea lisebelisoa li title tla hlahisoa karolong ea lisebelisoa. Haeba e le leshano, innerText thepa e tla sebelisoa ho kenya litaba ho DOM. Sebelisa mongolo haeba u tšoenyehile ka litlhaselo tsa XSS. |
offset |
sehlopha, khoele, mosebetsi | [0, 0] |
Offset ea lisebelisoa tse amanang le sepheo sa eona. O ka fetisa khoele ho litšobotsi tsa data tse nang le boleng bo arohaneng ba comma joalo ka: data-bs-offset="10,20" . Ha ts'ebetso e sebelisoa ho fumana qeto, e bitsoa ka ntho e nang le popper placement, reference, le popper rects e le khang ea eona ea pele. The triggering element DOM node e fetisitsoe e le khang ea bobeli. Mosebetsi o tlameha ho khutlisa sehlopha se nang le linomoro tse peli: skidding , distance . Ho fumana lintlha tse ling, sheba ho Popper's offset docs . |
placement |
khoele, mosebetsi | 'top' |
Mokhoa oa ho beha sesebelisoa: auto, holimo, tlase, ka ho le letšehali, ka ho le letona. Ha auto e se e hlalositsoe, e tla fetola sebopeho sa tooltip. Ha ts'ebetso e sebelisoa ho fumana hore na e behiloe hokae, e bitsoa ka node ea DOM e nang le "tooltip" e le khang ea eona ea pele, 'me karolo e qalang ea DOM e le ea bobeli. Moelelo this o behiloe ho mohlala oa lisebelisoa. |
popperConfig |
lefeela, ntho, tshebetso | null |
Ho fetola tlhophiso ea kamehla ea Bootstrap ea Popper, bona tlhophiso ea Popper . Ha ts'ebetso e sebelisoa ho theha tlhophiso ea Popper, e bitsoa ka ntho e nang le tlhophiso ea kamehla ea Bootstrap ea Popper. E u thusa ho sebelisa le ho kopanya ea kamehla le tlhophiso ea hau. Ts'ebetso e tlameha ho khutlisa ntho e hlophisitsoeng bakeng sa Popper. |
sanitize |
boolean | true |
Lumella kapa u tima tsamaiso ea sanitization. Haeba e kentsoe 'template' , 'content' 'me 'title' likhetho li tla hloekisoa. |
sanitizeFn |
null, tshebetso | null |
Mona o ka fana ka ts'ebetso ea hau ea sanitize. Sena se ka ba molemo haeba u khetha ho sebelisa laebrari e inehetseng ho etsa bohloeki. |
selector |
khoele, bohata | false |
Haeba ho fanoe ka sekhetho, lintlha tsa lisebelisoa li tla abeloa lipehelo tse boletsoeng. Ha e le hantle, sena se sebelisetsoa ho sebelisa lisebelisoa tsa lisebelisoa ho likarolo tsa DOM tse kenyelletsoeng ka matla ( jQuery.on tšehetso). Sheba taba ena le mohlala o rutang . |
template |
khoele | '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' |
HTML ea mantlha eo u ka e sebelisang ha u theha sesebelisoa. The tooltip's title e tla kenngoa ka har'a .tooltip-inner . .tooltip-arrow e tla fetoha motsu oa sesebelisoa. Karolo e ka ntle ea wrapper e lokela ho ba le .tooltip sehlopha le role="tooltip" . |
title |
khoele, element, mosebetsi | '' |
Boleng ba sehlooho sa kamehla haeba title semelo se le sieo. Haeba ts'ebetso e fanoe, e tla bitsoa ka this litšupiso tsa eona ho element eo popover e khomaretsoeng ho eona. |
trigger |
khoele | 'hover focus' |
Mokhoa oa lisebelisoa o qala joang: tobetsa, hover, tsepamisa maikutlo, tataiso. U ka 'na ua fetisa li-triggers tse ngata; di arole ka sebaka. 'manual' e bontša hore sesebelisoa se tla qalisoa ka mokhoa oa lenaneo ka .tooltip('show') , .tooltip('hide') le .tooltip('toggle') mekhoa; boleng bona bo ke ke ba kopanngoa le sesosa leha e le sefe se seng. 'hover' ka bohona ho tla fella ka malebela a lithulusi a ke keng a hlahisoa ka keyboard, 'me a lokela ho sebelisoa feela haeba mekhoa e meng ea ho fetisa tlhahisoleseling e tšoanang bakeng sa basebelisi ba keyboard e le teng. |
Litšobotsi tsa data bakeng sa lisebelisoa tsa motho ka mong
Likhetho tsa lisebelisoa tsa motho ka mong li ka hlalosoa ka tšebeliso ea lintlha, joalo ka ha ho hlalositsoe ka holimo.
Ho sebelisa ts'ebetso lepopperConfig
const tooltip = new bootstrap.Tooltip(element, {
popperConfig(defaultBsPopperConfig) {
// const newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Mekhoa
Mekhoa ea Asynchronous le liphetoho
Mekhoa eohle ea API ha e- synchronous 'me e qala phetoho . Ba khutlela ho motho ea letselitseng hang ha phetoho e qala empa pele e fela . Ho feta moo, mohala oa mokhoa ho karolo ea phetoho o tla hlokomolohuoa .
Sheba litokomane tsa rona tsa JavaScript bakeng sa lintlha tse ling .
Mokhoa | Tlhaloso |
---|---|
disable |
E tlosa bokhoni ba ho hlahisa lisebelisoa tsa element. The tooltip e tla khona ho bonts'oa ha feela e buletsoe hape. |
dispose |
E pata le ho senya sesebelisoa sa element (E tlosa data e bolokiloeng ho element ea DOM). Litlhahiso tse sebelisang kemiso (tse entsoeng ho sebelisoa khetho selector ) li ke ke tsa senngoa ka bonngoe holima lintho tse qalang. |
enable |
E fa ntlha ea lisebelisoa bokhoni ba ho bonts'oa. Litlhahiso tsa lisebelisoa li lumelloa ka mokhoa oa kamehla. |
getInstance |
Mokhoa o tsitsitseng o u lumellang hore u fumane mohlala oa lisebelisoa tse amanang le karolo ea DOM, kapa u thehe e ncha haeba e sa qalisoa. |
getOrCreateInstance |
Mokhoa o tsitsitseng o u lumellang hore u fumane mohlala oa lisebelisoa tse amanang le karolo ea DOM, kapa u thehe e ncha haeba e sa qalisoa. |
hide |
E pata ntlha ea lisebelisoa. E khutlela ho ea letselitseng pele sesebelisoa se patiloe (ke hore pele hidden.bs.tooltip ketsahalo e etsahala). Sena se nkuoa e le "manual" e qalang ea sesebelisoa. |
setContent |
E fana ka mokhoa oa ho fetola litaba tsa tooltip ka mor'a ho qala. |
show |
Reveals an element’s tooltip. Returns to the caller before the tooltip has actually been shown (i.e. before the shown.bs.tooltip event occurs). This is considered a “manual” triggering of the tooltip. Tooltips with zero-length titles are never displayed. |
toggle |
Toggles an element’s tooltip. Returns to the caller before the tooltip has actually been shown or hidden (i.e. before the shown.bs.tooltip or hidden.bs.tooltip event occurs). This is considered a “manual” triggering of the tooltip. |
toggleEnabled |
Toggles the ability for an element’s tooltip to be shown or hidden. |
update |
Updates the position of an element’s tooltip. |
const tooltip = bootstrap.Tooltip.getInstance('#example') // Returns a Bootstrap tooltip instance
// setContent example
tooltip.setContent({ '.tooltip-inner': 'another title' })
setContent
method accepts an
object
argument, where each property-key is a valid
string
selector within the popover template, and each related property-value can be
string
|
element
|
function
|
null
Events
Event | Description |
---|---|
hide.bs.tooltip |
This event is fired immediately when the hide instance method has been called. |
hidden.bs.tooltip |
This event is fired when the popover has finished being hidden from the user (will wait for CSS transitions to complete). |
inserted.bs.tooltip |
This event is fired after the show.bs.tooltip event when the tooltip template has been added to the DOM. |
show.bs.tooltip |
This event fires immediately when the show instance method is called. |
shown.bs.tooltip |
This event is fired when the popover has been made visible to the user (will wait for CSS transitions to complete). |
const myTooltipEl = document.getElementById('myTooltip')
const tooltip = bootstrap.Tooltip.getOrCreateInstance(myTooltipEl)
myTooltipEl.addEventListener('hidden.bs.tooltip', () => {
// do something...
})
tooltip.hide()