Svetuka kune chikuru content Svetuka kuenda kudocs navigation
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 . Iwe unofanirwa kusanganisira popper.min.js pamberi pebootstrap.js kana kushandisa bootstrap.bundle.min.js/ bootstrap.bundle.jsiyo ine Popper kuitira kuti matipi ekushandisa ashande!
  • 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.
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 .

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

Muenzaniso: Gonesa matipi ekushandisa kwese kwese

Imwe nzira yekutanga matipi ezvishandiso pane peji ndeyekuvasarudza nehunhu hwavo data-bs-toggle:

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  return new bootstrap.Tooltip(tooltipTriggerEl)
})

Mienzaniso

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.

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

Uye netsika HTML yakawedzerwa:

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

NeSVG:

Sass

Variables

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

Usage

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

Tamba chishandiso kuburikidza neJavaScript:

var exampleEl = document.getElementById('example')
var 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:

var exampleEl = document.getElementById('example')
var tooltip = new bootstrap.Tooltip(exampleEl, {
  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" 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".

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

Options

Sarudzo dzinogona kupfuudzwa kuburikidza nedata hunhu kana JavaScript. Nezve data hunhu, wedzera iyo sarudzo zita ku data-bs-, semu data-bs-animation="". Ita shuwa yekushandura iyo kesi mhando yezita resarudzo kubva kameraCase kuenda ku kebab-kesi kana uchipfuura sarudzo kuburikidza ne data hunhu. Semuenzaniso, pane kushandisa data-bs-customClass="beautifier", shandisa data-bs-custom-class="beautifier".

Ziva kuti nekuda kwezvikonzero zvekuchengetedza iyo sanitize,, sanitizeFnuye allowListsarudzo haigone kupihwa uchishandisa data hunhu.
Zita Type Default Tsanangudzo
animation boolean true Isa CSS fade shanduko kune tooltip
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.

delay nhamba | object 0

Kunonoka kuratidza uye kuvanza iyo tooltip (ms) - haishande kune manual trigger type

Kana nhamba yapihwa, kunonoka kunoiswa kune ese ari maviri hide/show

Chimiro chechinhu ndeichi:delay: { "show": 500, "hide": 100 }

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.

placement tambo | basa 'top'

Maitiro ekuisa iyo tooltip - auto | pamusoro | pasi | left | rudyi.
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.

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 izvi 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-arrowuchava museve wetipipi.

Iyo yekunze wrapper element inofanirwa kuve .tooltipnekirasi uye role="tooltip".

title tambo | chinhu | basa ''

Default title value kana titlehunhu husipo.

Kana basa rapihwa, rinodaidzwa nereferensi yayo thisyakaiswa kune chinhu chakasungirirwa mudziyo wekushandisa.

trigger tambo 'hover focus'

Maturusi ekushandisa anokonzereswa sei - tinya | hovha | focus | manual. Unogona kupfuura akawanda anokonzeresa; vaparadzanise nenzvimbo.

'manual'inoratidza kuti chishandiso chinokonzereswa nehurongwa kuburikidza ne .show(), .hide()uye .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.

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
boundary tambo | element '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 .
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.

sanitize boolean true Gonesa kana kudzima sanitization. Kana yakagadziriswa 'template'uye 'title'sarudzo dzichaitwa sanitized. Ona chikamu che sanitizer mune yedu JavaScript zvinyorwa .
allowList object Default value Chinhu chine hunhu uye ma tag anotenderwa
sanitizeFn null | basa null Pano iwe unogona kupa yako wega sanitize basa. Izvi zvinogona kubatsira kana ukada kushandisa raibhurari yakatsaurirwa kuita sanitization.
offset array | tambo | basa [0, 0]

Offset yetip yezvishandiso inoenderana nechinangwa chayo. Iwe unogona kupfuudza tambo mune data hunhu ine comma yakapatsanurwa kukosha 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, distance]

Kuti uwane rumwe ruzivo tarisa kuPopper's offset docs .

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 kumisikidzwa. Inokubatsira kushandisa uye kubatanidza iyo yakasarudzika neyako gadziriso. Basa racho rinofanira kudzorera chinhu chekugadzirisa chePopper.

Data maitiro kune ega ega ekushandisa

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

Kushandisa basa nepopperConfig

var tooltip = new bootstrap.Tooltip(element, {
  popperConfig: function (defaultBsPopperConfig) {
    // var 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 .

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.

tooltip.show()

hide

Inovanza zano rekushandisa. Inodzokera kune ari kufona chitupa chisati chavanzwa (kureva kuti hidden.bs.tooltipchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yeturusitip.

tooltip.hide()

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.

tooltip.toggle()

kurasa

Inoviga uye inoparadza chishandiso chechinhu (Inobvisa data rakachengetwa pachinhu cheDOM). Zvishandiso zvinoshandisa kugovera (zvinogadzirwa pachishandiswa sarudzoselector ) hazvingaparadzwi pachega pazvikamu zvinokonzeresa zvedzinza .

tooltip.dispose()

enable

Inopa chekushandisa chechinhu kugona kuratidzwa. Zvishandiso zvinogoneswa nekusarudzika.

tooltip.enable()

disable

Inobvisa kugona kwetip yechinhu kuti iratidzwe. Iyo tooltip inongokwanisa kuratidzwa kana yakabatidzwa zvakare.

tooltip.disable()

toggleEnabled

Inoshandura kugona kwetip yechinhu kuti ionekwe kana kuvanzwa.

tooltip.toggleEnabled()

update

Inogadziridza nzvimbo yetip yechinhu.

tooltip.update()

getInstance

Static nzira iyo inokutendera iwe kuti uwane iyo tooltip muenzaniso yakabatana neDOM chinhu

var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance

getOrCreateInstance

Static nzira iyo inokutendera iwe kuti uwane iyo tooltip muenzaniso yakabatana neDOM element, kana kugadzira imwe nyowani kana isina kutangwa.

var exampleTriggerEl = document.getElementById('example')
var tooltip = bootstrap.Tooltip.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance

Zviitiko

Chiitiko mhando Tsanangudzo
show.bs.tooltip Ichi chiitiko chinopisa nekukasira kana shownzira yemuenzaniso inodanwa.
shown.bs.tooltip Chiitiko ichi chinodzingwa kana chishandiso chaitwa kuti chionekwe kumushandisi (chinomirira kuti CSS shanduko ipedze).
hide.bs.tooltip Ichi chiitiko chinodzingwa nekukasira kana iyo hidemuenzaniso nzira yadaidzwa.
hidden.bs.tooltip Chiitiko ichi chinodzingwa kana chishandiso chapedza kuvanzwa kubva kumushandisi (chinomirira kuti CSS shanduko ipere).
inserted.bs.tooltip Chiitiko ichi chinodzingwa mushure show.bs.tooltipmechiitiko apo template yekushandisa yawedzerwa kuDOM.
var myTooltipEl = document.getElementById('myTooltip')
var tooltip = new bootstrap.Tooltip(myTooltipEl)

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

tooltip.hide()