Svetuka kune chikuru content Svetuka kuenda kudocs navigation
Check
in English

Tooltips

Zvinyorwa uye mienzaniso yekuwedzera tsika yeBootstrap matipi ekushandisa neCSS neJavaScript uchishandisa CSS3 yemaanimation uye data-bs-hunhu hwekuchengetera zita renzvimbo.

Overview

Zvinhu zvekuziva kana uchishandisa tooltip plugin:

  • Maturusi anotsamira pane yechitatu bato raibhurari Popper yekumisikidza . Unofanira kusanganisira popper.min.js pamberi bootstrap.js, kana kushandisa imwe bootstrap.bundle.min.jsine Popper.
  • Maturusi ndeekupinda nekuda kwezvikonzero zvekuita, saka iwe unofanirwa kuzvitangisa iwe pachako .
  • Zvishandiso zvine mazita akareba zero hazvimbotaridzwa.
  • Nyora container: 'body'kudzivirira kupa matambudziko muzvikamu zvakaoma zvikuru (semapoka edu ekuisa, mapoka emabhatani, nezvimwe).
  • Kuvhura matipi ekushandisa pazvinhu zvakavanzika hazvishande.
  • .disabledMaturusi ezvishandiso kana maelement disabledanofanira kukonzereswa pachinhu chekuputira.
  • Kana yakatangwa kubva kune hyperlink inotenderera mitsetse yakawanda, matipi ezvishandiso anozoiswa pakati. Shandisa white-space: nowrap;pane yako <a>kudzivirira maitiro aya.
  • Zvishandiso zvinofanirwa kuvanzwa zvisati zvabviswa zvinhu zvinoenderana nazvo muDOM.
  • Zvishandiso zvinogona kukonzereswa nekuda kwechinhu chiri mukati memumvuri DOM.

Une zvese izvozvo? Zvakanaka, ngationei kuti vanoshanda sei nemimwe mienzaniso.

Nekumisikidza, chikamu ichi chinoshandisa yakavakirwa-mukati sanitizer, iyo inobvisa chero zvinhu zveHTML zvisingabvumirwe zvakajeka. Ona chikamu che sanitizer mune yedu JavaScript zvinyorwa kuti uwane rumwe ruzivo.
Iyo animation mhedzisiro yechikamu ichi zvinoenderana prefers-reduced-motionnemubvunzo wenhau. Ona chikamu chakaderedzwa chezvinyorwa zvedu zvekusvikika .

Mienzaniso

Vhura matipi ekushandisa

Sezvataurwa pamusoro apa, unofanira kutanga maturusi ekushandisa asati ashandiswa. Imwe nzira yekutanga matipi ekushandisa pane peji ingave yekuvasarudza nehunhu hwavo, sekudaro data-bs-toggle:

const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))

Hover pamusoro pemalink ari pasi apa kuti uone maturusi ekushandisa:

Ruvara rwechibatiso kuratidza mamwe mainline link ane matipi ekushandisa. Uku kwave kungozadza, hapana mhondi. Zvemukati zvakaiswa pano kungotevedzera kuvepo kwemavara chaiwo . Uye zvese izvo zvekungokupa iwe zano rekuti maturusi aizoita sei kana ashandiswa mumamiriro ezvinhu epasirese. Saka ndinovimba watoona mashandisiro anoita aya maturusi pazvinongedzo anogona kushanda mukuita, kana wangoashandisa pane yako saiti kana purojekiti.

html
<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>
Inzwa wakasununguka kushandisa chero titlekana data-bs-titlemuHTML yako. Kana titleyashandiswa, Popper anoitsiva otomatiki data-bs-titlekana chinhu chaitwa.

Custom tooltips

Yakawedzerwa mu v5.2.0

Unogona kugadzirisa kutaridzika kwematipi ekushandisa uchishandisa CSS zvinosiyana . Isu tinoseta kirasi data-bs-custom-class="custom-tooltip"yetsika nekutarisa kutaridzika kwedu kwetsika uye kuishandisa kupfuudza yemuno CSS kusiyanisa.

.custom-tooltip {
  --bs-tooltip-bg: var(--bs-primary);
}
html
<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>

Nhungamiro

Famba pamusoro pemabhatani ari pazasi kuti uone mana ezvishandiso nzira: kumusoro, kurudyi, pasi, uye kuruboshwe. Mafambiro anotaridzwa kana uchishandisa Bootstrap muRTL.

<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>

Uye netsika HTML yakawedzerwa:

<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>

NeSVG:

CSS

Variables

Yakawedzerwa mu v5.2.0

Sechikamu cheBootstrap's evolving CSS variables approach, matipi ekushandisa zvino anoshandisa emuno CSS machinjiro pakusimudzira .tooltipchaiyo-nguva kugadzirisa. Hwaro hwemhando dzeCSS dzakaiswa kuburikidza neSass, saka Sass customization ichiri kutsigirwa, zvakare.

  --#{$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};
  

Sass zvakasiyana

$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

Usage

Iyo tooltip plugin inogadzira zvirimo uye markup pane inodiwa, uye neyakagadzika nzvimbo matipi eturusi mushure meiyo trigger element.

Tamba chishandiso kuburikidza neJavaScript:

const exampleEl = document.getElementById('example')
const tooltip = new bootstrap.Tooltip(exampleEl, options)
Kufashukira autouyescroll

Tooltip chinzvimbo chinoedza kuchinja otomatiki kana mudziyo wemubereki uine overflow: autokana overflow: scrollsewedu .table-responsive, asi uchiramba wakamisikidzwa. Kuti ugadzirise izvi, isa boundarysarudzo (yeiyo flip modifier uchishandisa popperConfigsarudzo) kune chero HTMLElement kuti ipfuure iyo yakasarudzika kukosha, 'clippingParents'senge document.body:

const tooltip = new bootstrap.Tooltip('#example', {
  boundary: document.body // or document.querySelector('#boundary')
})

Markup

Mucherechedzo unodiwa wetipi yeturusi ingori datahunhu uye titlepane HTML chinhu chaunoshuvira kuve nechokushandisa. Iyo yakagadzirwa markup yeturusitip iri nyore, kunyangwe ichida chinzvimbo (nekumisikidza, yakarongedzwa topneplugin).

Kugadzira matipi ekushandisa kune kiibhodhi uye vanobatsira tekinoroji vashandisi

Iwe unongo wedzera maturusi ezvishandiso kuHTML zvinhu zvinogara zvichitariswa kiibhodhi-inotariswa uye inopindirana (senge zvinongedzo kana mafomu ekudzora). Kunyangwe zvinopokana zveHTML zvinhu ( <span>senge s) zvichigona kuitwa kuti zvitarisike nekuwedzera tabindex="0"hunhu, izvi zvinowedzera zvinogona kutsamwisa uye zvinovhiringa tebhu inomira pazvinhu zvisiri-zvinopindirana zvevashandisi vekhibhodi, uye matekinoroji mazhinji anobatsira parizvino haazivise chishandiso mune ino mamiriro. Pamusoro pezvo, usavimbe nayo chete hoversechinhu chinokonzeresa chetipi chako chekushandisa, sezvo izvi zvichizoita kuti matipi ako eturusi asakwanise kukonzeresa vashandisi vekhibhodi.

<!-- 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>

Zvinhu zvakaremara

Zvinhu zvine disabledhunhu hazvidyidzane, zvichireva kuti vashandisi havagone kutarisa, kutenderedza, kana kudzvanya kuti vatange chishandiso (kana popover). Sekushanda, iwe unozoda kukonzeresa chishandiso kubva pakuputira <div>kana <span>, yakanyatsogadzirwa keyboard-inotariswa uchishandisa tabindex="0".

html
<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>

Options

Sezvo sarudzo dzichigona kupfuudzwa kuburikidza nedata hunhu kana JavaScript, unogona kuisa sarudzo zita ku data-bs-, semu data-bs-animation="{value}". Ita shuwa yekushandura mhando yekesi yezita resarudzo kubva ku " camelCase " kuenda ku " kebab-case " kana uchipfuura sarudzo kuburikidza ne data hunhu. Somuenzaniso, shandisa data-bs-custom-class="beautifier"pane data-bs-customClass="beautifier".

Kubva kuBootstrap 5.2.0, zvese zvinongedzo zvinotsigira muyedzo wakachengetedzwa data hunhu data-bs-confighunogona kuisa akareruka chechikamu kumisikidzwa setambo yeJSON. Kana chinhu chine data-bs-config='{"delay":0, "title":123}'uye data-bs-title="456"hunhu, kukosha kwekupedzisira titlekuchave 456uye iyo yakaparadzana data hunhu inodarika kukosha kwakapihwa pa data-bs-config. Pamusoro pezvo, hunhu huripo hwe data hunokwanisa kuisa hunhu hweJSON senge data-bs-delay='{"show":0,"hide":150}'.

Ziva kuti nekuda kwezvikonzero zvekuchengetedza iyo sanitize,, sanitizeFnuye allowListsarudzo haigone kupihwa uchishandisa data hunhu.
Zita Type Default Tsanangudzo
allowList object Default value Chinhu chine hunhu uye ma tag anotenderwa.
animation boolean true Isa CSS fade shanduko kune tooltip.
boundary tambo, chinhu 'clippingParents' Kufashukira kunomanikidza muganho wetip (inoshanda chete kune Popper's kudziviriraOverflow modifier). Nekusagadzikana 'clippingParents', ndeye uye inogona kugamuchira HTMLElement referensi (kuburikidza neJavaScript chete). Kuti uwane rumwe ruzivo tarisa kuPopper's detectOverflow docs .
container tambo, chinhu, nhema false Inoisa chitupa kune chimwe chinhu. Muenzaniso container: 'body':. Iyi sarudzo inonyanya kubatsira nekuti inokutendera iwe kuti uise iyo tooltip mukuyerera kwegwaro padhuze nechinhu chinokonzeresa - izvo zvinodzivirira iyo tooltip kuti isayangarara kubva kune inokonzeresa chinhu panguva yehwindo resize.
customClass tambo, basa '' Wedzera makirasi kune chishandiso kana charatidzwa. Ziva kuti makirasi aya achawedzerwa kune chero makirasi anotsanangurwa mutemplate. Kuwedzera makirasi akawanda, aparadzanise nenzvimbo: 'class-1 class-2'. Iwe unogona zvakare kupasa basa rinofanira kudzosa tambo imwe ine mamwe mazita ekirasi.
delay nhamba, chinhu 0 Kunonoka kuratidza uye kuviga chipitipi chekushandisa (ms)—hachishandi kurudzi rwekukonzeresa. Kana nhamba yapihwa, kunonoka kunoiswa kune ese ari maviri hide/show. Chimiro chechinhu ndeichi delay: { "show": 500, "hide": 100 }:.
fallbackPlacements array ['top', 'right', 'bottom', 'left'] Tsanangura nzvimbo dzekudzokera kumashure nekupa runyoro rwekuiswa muhurongwa (mukurongeka kwekuda). Kuti uwane rumwe ruzivo tarisa kuPopper's behaviour docs .
html boolean false Bvumira HTML muchokushandisa. Kana chiri chokwadi, ma tag eHTML ari mutooltip titleanozopihwa mutooltip. Kana zvisiri izvo, innerTextzvivakwa zvichashandiswa kuisa zvirimo muDOM. Shandisa zvinyorwa kana uchinetseka nezve XSS kurwiswa.
offset hurongwa, tambo, basa [0, 0] Offset yetip yezvishandiso inoenderana nechinangwa chayo. Iwe unogona kupfuudza tambo mune data hunhu uine comma akapatsanurwa maitiro senge: data-bs-offset="10,20". Kana basa rinoshandiswa kuona kumisa, rinodanwa nechinhu chine popper placement, referensi, uye popper rects senharo yayo yekutanga. Iyo inokonzeresa element DOM node inopfuudzwa seyechipiri nharo. Basa racho rinofanira kudzosa rondedzero ine nhamba mbiri: skidding , chinhambwe . Kuti uwane rumwe ruzivo tarisa kuPopper's offset docs .
placement tambo, basa 'top' Maitiro ekuisa iyo tooltip: otomatiki, pamusoro, pasi, kuruboshwe, kurudyi. Kana autoyatsanangurwa, ichaita dynamically reoring the tooltip. Kana basa rikashandiswa kuona kuiswa, rinodanwa neturusipi DOM node senharo yayo yekutanga uye chinokonzeresa chinhu DOM node sechipiri. Mamiriro thisacho akaiswa kumuenzaniso wetipi.
popperConfig null, chinhu, basa null Kuti uchinje Bootstrap's default Popper config, ona Popper's configuration . Kana basa richishandiswa kugadzira iyo Popper kumisikidzwa, inodanwa nechinhu chine Bootstrap's default Popper kumisikidza. Inokubatsira kushandisa uye kubatanidza iyo yakasarudzika neyako gadziriso. Basa racho rinofanira kudzorera chinhu chekugadzirisa chePopper.
sanitize boolean true Gonesa kana kudzima sanitization. Kana ikashandiswa 'template', 'content'uye 'title'sarudzo dzichacheneswa.
sanitizeFn null, basa null Pano iwe unogona kupa yako wega sanitize basa. Izvi zvinogona kubatsira kana ukada kushandisa raibhurari yakatsaurirwa kuita sanitization.
selector tambo, nhema false Kana sarudzo yakapihwa, zviro zveturusi zvinopihwa kune izvo zvakatarwa. Mukuita, izvi zvinoshandiswa kushandisawo matipi ekushandisa kune zvine simba akawedzera DOM zvinhu ( jQuery.onrutsigiro). Ona chinyorwa ichi uye muenzaniso unodzidzisa .
template tambo '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' Base HTML yekushandisa paunenge uchigadzira iyo tooltip. The tooltip's titleichabaiwa mu .tooltip-inner. .tooltip-arrowrichava museve wepfuti. Iyo yekunze wrapper element inofanirwa kuve .tooltipnekirasi uye role="tooltip".
title tambo, chinhu, basa '' Default title value kana titlehunhu husipo. Kana basa rakapihwa, rinodaidzwa nereferensi yaro thisyakaiswa kune chinhu icho popover inonamatira.
trigger tambo 'hover focus' Maturusi ekushandisa anokonzereswa sei: tinya, hover, tarisa, bhuku. Unogona kupfuura akawanda anokonzeresa; vaparadzanise nenzvimbo. 'manual'inoratidza kuti chishandiso chinokonzereswa nehurongwa kuburikidza ne .tooltip('show'), .tooltip('hide')uye .tooltip('toggle')nzira; kukosha uku hakugone kusanganiswa nechimwe chinokonzeresa. 'hover'pachezvayo zvinozoguma nematurusi ezvishandiso asingakwanise kuvhurwa kuburikidza nekhibhodi, uye anofanirwa kushandiswa chete kana dzimwe nzira dzekuburitsa ruzivo rwakafanana kune vashandisi vekhibhodi iripo.

Data maitiro kune ega ega ekushandisa

Sarudzo dzematurusi ega ega dzinogona kutsanangurwa neimwe nzira kuburikidza nekushandisa data hunhu, sezvatsanangurwa pamusoro.

Kushandisa basa nepopperConfig

const tooltip = new bootstrap.Tooltip(element, {
  popperConfig(defaultBsPopperConfig) {
    // const newPopperConfig = {...}
    // use defaultBsPopperConfig if needed...
    // return newPopperConfig
  }
})

Nzira

Asynchronous nzira uye shanduko

Yese nzira dzeAPI dzine asynchronous uye dzinotanga shanduko . Vanodzokera kumunhu anenge afona pachangotanga shanduko asi isati yapera . Pamusoro pezvo, kufona kwenzira pachikamu chekuchinja kuchafuratirwa .

Ona zvinyorwa zvedu zveJavaScript kuti uwane rumwe ruzivo .

Nzira Tsanangudzo
disable Inobvisa kugona kwetip yechinhu kuti iratidzwe. Iyo tooltip inongokwanisa kuratidzwa kana yakabatidzwa zvakare.
dispose Inoviga uye inoparadza chishandiso chechinhu (Inobvisa data rakachengetwa pachinhu cheDOM). Zvishandiso zvinoshandisa kugovera (zvinogadzirwa pachishandiswa sarudzoselector ) hazvingaparadzwi pachega pazvikamu zvinokonzeresa zvedzinza .
enable Inopa chekushandisa chechinhu kugona kuratidzwa. Zvishandiso zvinogoneswa nekusarudzika.
getInstance Static nzira iyo inokutendera iwe kuti uwane iyo tooltip muenzaniso yakabatana neDOM chinhu, kana kugadzira imwe nyowani kana isina kutangwa.
getOrCreateInstance Static nzira iyo inokutendera iwe kuti uwane iyo tooltip muenzaniso yakabatana neDOM chinhu, kana kugadzira imwe nyowani kana isina kutangwa.
hide Inovanza zano rekushandisa. Inodzokera kune ari kufona chitupa chisati chavanzwa (kureva kuti hidden.bs.tooltipchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yeturusitip.
setContent Inopa nzira yekushandura zvirimo zveturusi mushure mekutanga kwayo.
show Inoratidza chekushandisa chechinhu. Inodzokera kumunhu arikufona tip rekushandisa risati ranyatsoratidzwa (kureva kuti shown.bs.tooltipchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yeturusitip. Zvishandiso zvine mazita akareba zero hazvimbotaridzwa.
toggle Inoshandura matipi echinhu. Inodzokera kune ari kufona chitupa chisati charatidzwa kana kuvanzwa (kureva kuti shown.bs.tooltipkana hidden.bs.tooltipchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yeturusitip.
toggleEnabled Inoshandura kugona kwetip yechinhu kuti ionekwe kana kuvanzwa.
update Inogadziridza nzvimbo yetip yechinhu.
const tooltip = bootstrap.Tooltip.getInstance('#example') // Returns a Bootstrap tooltip instance

// setContent example
tooltip.setContent({ '.tooltip-inner': 'another title' })
Iyo setContentnzira inogamuchira objectnharo, apo imwe neimwe-kiyi-kiyi isarudzo inoshanda stringmukati mepopover template, uye imwe neimwe inoenderana pfuma-value inogona kuva string| element| function| null

Zviitiko

Chiitiko Tsanangudzo
hide.bs.tooltip Ichi chiitiko chinodzingwa nekukasira kana iyo hidemuenzaniso nzira yadaidzwa.
hidden.bs.tooltip Ichi chiitiko chinodzingwa kana popover yapedza kuvanzwa kubva kumushandisi (inomirira kuti CSS shanduko ipedze).
inserted.bs.tooltip Chiitiko ichi chinodzingwa mushure show.bs.tooltipmechiitiko apo template yekushandisa yawedzerwa kuDOM.
show.bs.tooltip Ichi chiitiko chinopisa nekukasira kana shownzira yemuenzaniso inodanwa.
shown.bs.tooltip Ichi chiitiko chinodzingwa kana popover yaitwa kuti ionekwe kumushandisi (inomirira kuti CSS shanduko ipedze).
const myTooltipEl = document.getElementById('myTooltip')
const tooltip = bootstrap.Tooltip.getOrCreateInstance(myTooltipEl)

myTooltipEl.addEventListener('hidden.bs.tooltip', () => {
  // do something...
})

tooltip.hide()