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 motho oa boraro Popper bakeng sa maemo. U tlameha ho kenyelletsa popper.min.js pele ho bootstrap.js kapa sebelisa
bootstrap.bundle.min.js
/bootstrap.bundle.js
e nang le Popper e le hore lisebelisoa tsa lisebelisoa li sebetse! - 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.
prefers-reduced-motion
potso ea media. Sheba karolo e
fokolitsoeng ea motsamao oa litokomane tsa phihlello ea rona .
O nale tseo tsohle? E kholo, a re boneng hore na ba sebetsa joang ka mehlala e meng.
Mohlala: Lumella lithulusi hohle
Tsela e 'ngoe ea ho qala lisebelisoa tsohle tse leqepheng e tla ba ho li khetha ka data-bs-toggle
tšobotsi ea tsona:
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
Mehlala
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.
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" 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>
'Me ka HTML e tloaelehileng e ekelitsoe:
<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>
Ka SVG:
Sass
Lintho tse fapaneng
$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;
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:
var exampleEl = document.getElementById('example')
var 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
:
var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, {
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" 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" title="Disabled tooltip">
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>
Dikgetho
Likhetho li ka fetisoa ka lintlha tsa data kapa JavaScript. Bakeng sa litšobotsi tsa data, kenya lebitso la khetho ho data-bs-
, joalo ka data-bs-animation=""
. Etsa bonnete ba hore o fetola mofuta oa nyeoe ea lebitso la khetho ho tloha ho camelCase ho ea ho kebab-case ha o fetisa likhetho ka litšobotsi tsa data. Ka mohlala, ho e-na le ho sebelisa data-bs-customClass="beautifier"
, sebelisa data-bs-custom-class="beautifier"
.
sanitize
,
sanitizeFn
, le
allowList
likhetho li ke ke tsa fanoa ho sebelisoa litšobotsi tsa data.
Lebitso | Mofuta | Ea kamehla | Tlhaloso |
---|---|---|---|
animation |
boolean | true |
Kenya phetoho ea CSS fade ho tooltip |
container |
khoele | ntho | bohata | false |
E kopanya ntlha ea lisebelisoa ho ntho e itseng. Mohlala |
delay |
nomoro | ntho | 0 |
Ho lieha ho bonts'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 Sebopeho sa ntho ke: |
html |
boolean | false |
Lumella HTML karolong ea lisebelisoa. Haeba ke 'nete, li-tag tsa HTML tse karolong ea lisebelisoa li Sebelisa mongolo haeba u tšoenyehile ka litlhaselo tsa XSS. |
placement |
khoele | tshebetso | 'top' |
Mokhoa oa ho beha sesebelisoa - auto | holimo | tlase | le letšehali | hantle. 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 |
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). Bona sena 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
Karolo e ka ntle ea wrapper e lokela ho ba le |
title |
khoele | ntho | tshebetso | '' |
Boleng ba sehlooho sa kamehla haeba Haeba mosebetsi o fanoe, o tla bitsoa ka |
trigger |
khoele | 'hover focus' |
Mokhoa oa lisebelisoa o qala joang - tobetsa | hloella | tsepamisa | tataiso. U ka 'na ua fetisa li-triggers tse ngata; di arole ka sebaka.
|
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). Bakeng sa tlhaiso-leseling e batsi, sheba litokomane tsa Popper tsa boitšoaro |
boundary |
khoele | element | 'clippingParents' |
Moeli o thibelang ho phalla ha sesebelisoa (e sebetsa feela ho Popper's preventOverflow modifier). Ka mokhoa o 'clippingParents' ikhethileng ke 'me e ka amohela tšupiso ea HTMLElement (ka JavaScript feela). Ho fumana lintlha tse ling, sheba ho Popper's detectOverflow docs . |
customClass |
khoele | tshebetso | '' |
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: U ka fetisa tšebetso e lokelang ho khutlisa khoele e le 'ngoe e nang le mabitso a sehlopha sa tlatsetso. |
sanitize |
boolean | true |
Lumella kapa u tima tsamaiso ea sanitization. Haeba e kentsoe 'template' 'me 'title' likhetho li tla hloekisoa. Sheba karolo ea sanitizer litokomaneng tsa rona tsa JavaScript . |
allowList |
ntho | Boleng ba kamehla | Ntho e nang le litšobotsi le li-tag tse lumelletsoeng |
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. |
offset |
sehlopha | khoele | tshebetso | [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: 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: . Ho fumana lintlha tse ling, sheba ho Popper's offset docs . |
popperConfig |
null | 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. |
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
var tooltip = new bootstrap.Tooltip(element, {
popperConfig: function (defaultBsPopperConfig) {
// var 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 .
bontsha
E senola karolo ea lisebelisoa. E kgutlela ho moletsi pele thulusi e bontshwa (ke hore pele shown.bs.tooltip
ketsahalo e etsahala). Sena se nkuoa e le "manual" e qalang ea sesebelisoa. Lisebelisoa tse nang le lihlooho tsa bolelele ba zero ha li hlahisoe.
tooltip.show()
pata
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.
tooltip.hide()
toggle
E fetola ntlha ea lisebelisoa. E khutlela ho ea letselitseng pele sesebelisoa se bontšoa kapa se patiloe (ke hore pele ketsahalo shown.bs.tooltip
kapa hidden.bs.tooltip
ketsahalo e etsahala). Sena se nkuoa e le "manual" e qalang ea sesebelisoa.
tooltip.toggle()
lahla
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.
tooltip.dispose()
nolofalletsa
E fa ntlha ea lisebelisoa bokhoni ba ho bonts'oa. Litlhahiso tsa lisebelisoa li lumelloa ka mokhoa oa kamehla.
tooltip.enable()
tima
E tlosa bokhoni ba ho hlahisa lisebelisoa tsa element. The tooltip e tla khona ho bonts'oa ha feela e buletsoe hape.
tooltip.disable()
toggleEnabled
E fetola bokhoni ba sesebelisoa sa element hore se bontšoe kapa se patehe.
tooltip.toggleEnabled()
nchafatsa
E kaonefatsa boemo ba ntlha ea lisebelisoa.
tooltip.update()
getInstance
Mokhoa o tsitsitseng o o lumellang ho fumana mohlala oa sesebelisoa o amanang le karolo ea DOM
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
getOrCreateInstance
Mokhoa o tsitsitseng o o lumellang ho fumana mohlala oa lisebelisoa tse amanang le ntho ea DOM, kapa u thehe e ncha haeba e sa qalisoa.
var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
Liketsahalo
Mofuta oa ketsahalo | Tlhaloso |
---|---|
show.bs.tooltip |
Ketsahalo ena e tuka hang hang ha show mokhoa oa mohlala o bitsoa. |
shown.bs.tooltip |
Ketsahalo ena e ts'oaroa ha sesebelisoa sa lisebelisoa se bonahalitsoe ho mosebelisi (e tla emela hore liphetoho tsa CSS li phethehe). |
hide.bs.tooltip |
Ketsahalo ena e lelekoa hang hang ha hide mokhoa oa mohlala o bitsoa. |
hidden.bs.tooltip |
Ketsahalo ena e ts'oaroa ha sesebelisoa se qeta ho patoa ho mosebelisi (e tla emela hore liphetoho tsa CSS li phethehe). |
inserted.bs.tooltip |
Ketsahalo ena e lelekoa ka mor'a show.bs.tooltip ketsahalo ea ha thempleite ea tooltip e kentsoe ho DOM. |
var myTooltipEl = document.getElementById('myTooltip')
var tooltip = new bootstrap.Tooltip(myTooltipEl)
myTooltipEl.addEventListener('hidden.bs.tooltip', function () {
// do something...
})
tooltip.hide()