Pitani kuzinthu zazikulu Pitani kumayendedwe adocs
Check
in English

Malangizo

Zolemba ndi zitsanzo zowonjezerera zida za Bootstrap ndi CSS ndi JavaScript pogwiritsa ntchito CSS3 pamakanema ndi ma data-bs-makhumbo osungira mitu yanu.

Mwachidule

Zomwe muyenera kudziwa mukamagwiritsa ntchito pulogalamu yowonjezera:

  • Zida zimadalira laibulale ya gulu lachitatu Popper kuti ikhazikike. Muyenera kuphatikiza popper.min.js m'mbuyomu bootstrap.js, kapena gwiritsani ntchito bootstrap.bundle.min.jsyomwe ili ndi Popper.
  • Zida ndizolowera pazifukwa zogwirira ntchito, chifukwa chake muyenera kuziyambitsa nokha .
  • Zida zokhala ndi mitu zazitali sizimawonetsedwa.
  • Nenani container: 'body'kuti mupewe kupereka zovuta muzinthu zovuta kwambiri (monga magulu athu olowetsa, magulu a batani, ndi zina).
  • Kuyambitsa zida zazinthu zobisika sikungagwire ntchito.
  • Zida .disabledkapena disabledzinthu ziyenera kuyambitsidwa pa chinthu chokulunga.
  • Zikayambika kuchokera ku ma hyperlink omwe amatambasula mizere ingapo, nsonga za zida zidzakhazikika. Gwiritsani white-space: nowrap;ntchito zanu <a>kuti mupewe izi.
  • Zida ziyenera kubisika zisanachotsedwe mu DOM.
  • Zida zitha kuyambika chifukwa cha chinthu chomwe chili mkati mwa mthunzi wa DOM.

Muli nazo zonse? Chabwino, tiyeni tiwone momwe amagwirira ntchito ndi zitsanzo zina.

Mwachikhazikitso, chigawochi chimagwiritsa ntchito sanitizer yomwe ili mkati, yomwe imachotsa zinthu zilizonse za HTML zomwe siziloledwa. Onani gawo la sanitizer muzolemba zathu za JavaScript kuti mumve zambiri.
Kanema wa gawoli amadalira prefers-reduced-motionfunso la media. Onani gawo lochepetsedwa la zolemba zathu zofikira .

Zitsanzo

Yambitsani zida zothandizira

Monga tafotokozera pamwambapa, muyenera kuyambitsa zida zothandizira musanagwiritse ntchito. Njira imodzi yokhazikitsira zida zonse patsamba ingakhale kuwasankha malinga ndi momwe data-bs-togglealili, monga:

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

Yendani pamwamba pa maulalo omwe ali pansipa kuti muwone zida zothandizira:

Mawu okhala ndi malo kuti awonetse maulalo apaintaneti okhala ndi zida. Uku ndi kungodzaza chabe, palibe wakupha. Zomwe zayikidwa pano kuti zingotengera kupezeka kwa zolemba zenizeni . Ndipo zonsezo kuti ndikupatseni lingaliro la momwe zida zimawonekera zikagwiritsidwa ntchito muzochitika zenizeni. Chifukwa chake mwachiyembekezo mwawona momwe zida zolumikizirana zimagwirira ntchito, mukazigwiritsa ntchito patsamba lanu kapena polojekiti yanu.

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>
Khalani omasuka kugwiritsa ntchito titlekapena data-bs-titlemu HTML yanu. Ikagwiritsidwa titlentchito, Popper amazilowetsa m'malo mwake data-bs-titlepomwe chinthucho chikuperekedwa.

Zothandizira mwamakonda

Yowonjezedwa mu v5.2.0

Mutha kusintha mawonekedwe a zida pogwiritsa ntchito mitundu ya CSS . Timakhazikitsa kalasi yokhazikika data-bs-custom-class="custom-tooltip"kuti iwonetsere mawonekedwe athu ndikugwiritsa ntchito kupitilira kusintha kwa CSS komweko.

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

Mayendedwe

Yendani pamwamba pa mabatani omwe ali pansipa kuti muwone njira zinayi zazida: pamwamba, kumanja, pansi, ndi kumanzere. Mayendedwe amawonekera mukamagwiritsa ntchito Bootstrap mu 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>

Ndipo ndi HTML yachizolowezi yowonjezedwa:

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

Ndi SVG:

CSS

Zosintha

Yowonjezedwa mu v5.2.0

Monga gawo la njira yosinthira ya CSS ya Bootstrap, zida zogwiritsira ntchito tsopano zimagwiritsa ntchito zosintha za CSS zakumaloko .tooltipkuti zisinthidwe zenizeni zenizeni. Makhalidwe amitundu ya CSS amayikidwa kudzera pa Sass, kotero makonda a Sass akadali othandizidwa, nawonso.

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

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

Kugwiritsa ntchito

Pulogalamu yowonjezera ya tooltip imapanga zokhutira ndi zolembera zomwe zimafunidwa, ndipo mwachisawawa zimayika zida pambuyo pa zomwe zimayambitsa.

Yambitsani chida kudzera pa JavaScript:

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

Malo a Tooltip amayesa kusintha okha ngati chotengera cha makolo chili nacho overflow: autokapena overflow: scrollngati makonda athu .table-responsive, komabe chimasunga malo omwe adayikapo. Kuti muthetse izi, ikani boundarykusankha (kwa flip modifier pogwiritsa ntchito popperConfignjirayo) ku HTMLElement iliyonse kuti iwononge mtengo wokhazikika, 'clippingParents'monga document.body:

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

Markup

Cholembera chofunikira pa chida ndi mawonekedwe chabe datandipo titlepa chinthu cha HTML mukufuna kukhala ndi chida. Zolemba zopangira zida ndizosavuta, ngakhale zimafunikira malo (mwachisawawa, zokhazikitsidwa topndi pulogalamu yowonjezera).

Kupanga zida zothandizira ogwiritsa ntchito kiyibodi ndi ukadaulo wothandizira

Muyenera kungowonjezera zida kuzinthu za HTML zomwe nthawi zambiri zimakhala zolunjika pa kiyibodi komanso zolumikizana (monga maulalo kapena zowongolera mawonekedwe). Ngakhale zinthu zosasintha za HTML (monga <span>s) zitha kukhala zowoneka bwino powonjezera mawonekedwe tabindex="0", izi zitha kuwonjezera zokhumudwitsa komanso zosokoneza pa zinthu zomwe sizimalumikizana ndi ogwiritsa ntchito kiyibodi, ndipo matekinoloje ambiri othandizira pakadali pano salengeza zachida ichi. Kuphatikiza apo, musamangodalira hoverngati choyambitsa chida chanu, chifukwa izi zipangitsa kuti zida zanu zikhale zosatheka kuyambitsa ogwiritsa ntchito kiyibodi.

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

Zinthu zolemala

Zinthu zomwe zili ndi mawonekedwe disabledake sizimayenderana, kutanthauza kuti ogwiritsa ntchito sangathe kuyang'ana, kuyang'ana pamwamba, kapena kuzidina kuti ayambitse chida (kapena popover). Monga njira yogwirira ntchito, mudzafuna kuyambitsa chida kuchokera pa chokulunga <div>kapena <span>, chopangidwa kuti chikhale chokhazikika pogwiritsa ntchito 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>

Zosankha

Monga zosankha zitha kuperekedwa kudzera pa data kapena JavaScript, mutha kuwonjezera dzina lachisankho ku data-bs-, monga data-bs-animation="{value}". Onetsetsani kuti musinthe mtundu wamtundu wa dzina lachisankho kuchokera ku " camelCase " kupita ku " kebab-case " podutsa zosankha pogwiritsa ntchito zizindikiro za data. Mwachitsanzo, gwiritsani ntchito data-bs-custom-class="beautifier"m'malo mwa data-bs-customClass="beautifier".

Kuyambira pa Bootstrap 5.2.0, zigawo zonse zimathandizira chidziwitso chosungidwa cha data data-bs-configchomwe chingathe kukhazikitsa chigawo chosavuta ngati chingwe cha JSON. Chilichonse chikakhala ndi mawonekedwe , mtengo womaliza udzakhala ndipo mawonekedwe osiyana a data adzapitilira zomwe zaperekedwa data-bs-config='{"delay":0, "title":123}'pa . Kuphatikiza apo, zomwe zilipo kale zimatha kusunga ma JSON monga .data-bs-title="456"title456data-bs-configdata-bs-delay='{"show":0,"hide":150}'

Dziwani kuti pazifukwa zachitetezo sanitize, sanitizeFn, ndi allowListzosankha sizingaperekedwe pogwiritsa ntchito mawonekedwe a data.
Dzina Mtundu Zosasintha Kufotokozera
allowList chinthu Mtengo wofikira Chinthu chomwe chili ndi zovomerezeka ndi ma tag.
animation boolean true Ikani kusintha kwa CSS pazida.
boundary chingwe, element 'clippingParents' Malire oletsa kusefukira a chida (zimagwira ntchito pa Popper's preventOverflow modifier). Mwachikhazikitso, ndi 'clippingParents'ndipo chitha kuvomereza HTMLElement reference (kudzera JavaScript kokha). Kuti mudziwe zambiri onani zolemba za Popper's detectOverflow .
container chingwe, chinthu, zabodza false Imawonjezera chida ku chinthu china. Chitsanzo: container: 'body'. Njirayi ndiyothandiza kwambiri chifukwa imakulolani kuti muyike chidacho pakuyenda kwa chikalatacho pafupi ndi chinthu choyambitsa - zomwe zingalepheretse chidacho kuti chisayandama kuchoka pachoyambitsacho pakusintha kwazenera.
customClass chingwe, ntchito '' Onjezani makalasi pazida zomwe zikuwonetsedwa. Dziwani kuti makalasi awa adzawonjezedwa kuwonjezera pa makalasi aliwonse omwe afotokozedwa mu template. Kuti muwonjezere makalasi angapo, alekanitseni ndi mipata: 'class-1 class-2'. Mukhozanso kupereka ntchito yomwe iyenera kubweza chingwe chimodzi chokhala ndi mayina owonjezera amagulu.
delay nambala, chinthu 0 Kuchedwetsa kusonyeza ndi kubisa chida (ms)—sikugwira ntchito pa mtundu woyambitsa pamanja. Ngati nambala yaperekedwa, kuchedwetsa kumayikidwa pazithunzi zonse ziwiri. Kapangidwe kazinthu ndi delay: { "show": 500, "hide": 100 }:.
fallbackPlacements gulu ['top', 'right', 'bottom', 'left'] Tanthauzirani malo obwerera m'mbuyo popereka mndandanda wamayikidwe angapo (molingana ndi zokonda). Kuti mudziwe zambiri onani za Popper's behaviour docs .
html boolean false Lolani HTML pazida. Ngati ndi zoona, ma tag a HTML mu tooltip's titleadzawonetsedwa pazothandizira. Ngati zabodza, innerTextkatundu adzagwiritsidwa ntchito kuyika zomwe zili mu DOM. Gwiritsani ntchito mawu ngati mukuda nkhawa ndi kuukira kwa XSS.
offset gulu, chingwe, ntchito [0, 0] Kuchotsera kwa chida chogwirizana ndi chandamale chake. Mutha kudutsa zingwe zama data okhala ndi ma comma olekanitsidwa monga: data-bs-offset="10,20". Ntchito ikagwiritsidwa ntchito kutsimikizira kuchotsera, imatchedwa ndi chinthu chomwe chili ndi popper, zolozera, ndi popper rects ngati mkangano wake woyamba. Choyambitsa chinthu cha DOM node chimadutsa ngati mkangano wachiwiri. Ntchitoyi iyenera kubweza mndandanda wokhala ndi manambala awiri: skidding , mtunda . Kuti mumve zambiri onani za Popper's offset docs .
placement chingwe, ntchito 'top' Momwe mungayikitsire chida: auto, pamwamba, pansi, kumanzere, kumanja. Ikanenedwa auto, imawongoleranso chida chothandizira. Ntchito ikagwiritsidwa ntchito kudziwa malo, imatchedwa ndi chida cha DOM node ngati mtsutso wake woyamba ndi chinthu choyambitsa DOM node ngati yachiwiri. Nkhaniyi thisimayikidwa ku chitsanzo cha tooltip.
popperConfig null, chinthu, ntchito null Kuti musinthe kasinthidwe ka Popper ka Bootstrap, onani kasinthidwe ka Popper . Ntchito ikagwiritsidwa ntchito kupanga masinthidwe a Popper, imatchedwa ndi chinthu chomwe chili ndi kasinthidwe ka Popper ka Bootstrap. Zimakuthandizani kugwiritsa ntchito ndikuphatikiza zokhazikika ndi kasinthidwe kanu. Ntchitoyi iyenera kubweza chinthu chosinthira cha Popper.
sanitize boolean true Yambitsani kapena kuletsa ukhondo. Ngati adamulowetsa 'template', 'content'ndipo 'title'zosankha zidzayeretsedwa.
sanitizeFn null, ntchito null Apa mutha kupereka ntchito yanu ya sanitize. Izi zitha kukhala zothandiza ngati mukufuna kugwiritsa ntchito laibulale yodzipatulira kuchita ukhondo.
selector chingwe, zabodza false Ngati chosankha chaperekedwa, zida zopangira zida zidzaperekedwa ku zomwe zafotokozedwazo. M'malo mwake, izi zimagwiritsidwanso ntchito kugwiritsa ntchito zida zothandizira pazinthu zowonjezera za DOM ( jQuery.onthandizo). Onani nkhaniyi ndi chitsanzo chothandiza .
template chingwe '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' Base HTML kuti mugwiritse ntchito popanga chida. The tooltip's adzabayidwa titlemu .tooltip-inner. .tooltip-arrowadzakhala muvi wa chida. Chovala chakunja chiyenera kukhala ndi .tooltipkalasi ndi role="tooltip".
title chingwe, chinthu, ntchito '' Mtengo wamutu wotsikirapo ngati titlechizindikirocho palibe. Ngati ntchito yaperekedwa, thisidzayitanidwa ndi zolemba zake ku chinthu chomwe popover amamangiriridwa.
trigger chingwe 'hover focus' Momwe chida chimayambira: dinani, kusuntha, kuyang'ana, pamanja. Mutha kudutsa zoyambitsa zambiri; alekanitse iwo ndi danga. 'manual'zikuwonetsa kuti chidacho chidzayambika mwadongosolo kudzera mu .tooltip('show'), .tooltip('hide')ndi .tooltip('toggle')njira; mtengo uwu sungathe kuphatikizidwa ndi choyambitsa china chilichonse. 'hover'pachokha zidzabweretsa zida zomwe sizingayambitsidwe kudzera pa kiyibodi, ndipo ziyenera kugwiritsidwa ntchito ngati njira zina zotumizira uthenga womwewo kwa ogwiritsa ntchito kiyibodi zilipo.

Mawonekedwe a data pazida zapayekha

Zosankha za zida zapayekha zitha kufotokozedwa pogwiritsa ntchito mawonekedwe a data, monga tafotokozera pamwambapa.

Kugwiritsa ntchito ndipopperConfig

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

Njira

Asynchronous njira ndi kusintha

Njira zonse za API ndizosasinthika ndipo zimayamba kusintha . Amabwerera kwa woyimbayo atangoyamba kusintha koma asanathe . Kuonjezera apo, kuyitana kwa njira pa gawo losintha kudzanyalanyazidwa .

Onani zolemba zathu za JavaScript kuti mudziwe zambiri .

Njira Kufotokozera
disable Imachotsa kuthekera kwa chida cha chinthu kuti chiwonetsedwe. Zidazi zitha kuwonetsedwa pokhapokha zitayatsidwanso.
dispose Imabisa ndi kuwononga chida cha chinthu (Imachotsa deta yosungidwa pa chinthu cha DOM). Zida zomwe zimagwiritsa ntchito kugawira ena (omwe amapangidwa pogwiritsa ntchito selectorkusankha ) sizingawonongeke pazigawo zoyambitsa mbadwa.
enable Imapatsa chida cha chinthu kuti chiwonetsedwe. Zothandizira zimayatsidwa mwachisawawa.
getInstance Njira yosasunthika yomwe imakupatsani mwayi wopeza chida cholumikizidwa ndi chinthu cha DOM, kapena pangani china china ngati sichinayambike.
getOrCreateInstance Njira yosasunthika yomwe imakupatsani mwayi wopeza chida cholumikizidwa ndi chinthu cha DOM, kapena pangani china china ngati sichinayambike.
hide Imabisa chida cha chinthu. Imabwerera kwa woyimbirayo chida chisanabisike (ie zisanachitike hidden.bs.tooltip). Izi zimatengedwa ngati "kuyambitsa" kwa chida chothandizira.
setContent Imapereka njira yosinthira zomwe zili patsamba lazothandizira pambuyo poyambitsa.
show Imawulula zida za chinthu. Imabwerera kwa woyimbirayo chida chisanasonyezedwe (ie zisanachitike shown.bs.tooltip). Izi zimatengedwa ngati "kuyambitsa" kwa chida chothandizira. Zida zokhala ndi mitu zazitali sizimawonetsedwa.
toggle Imatembenuza chida cha chinthu. Imabwerera kwa woyimbirayo chida chisanasonyezedwe kapena kubisidwa (ie chisanachitike shown.bs.tooltipkapena hidden.bs.tooltipchochitikacho). Izi zimatengedwa ngati "kuyambitsa" kwa chida chothandizira.
toggleEnabled Imasintha kuthekera kwa chida cha chinthu kuti chiwonetsedwe kapena kubisika.
update Imakonzanso pomwe pali chida cha chinthu.
const tooltip = bootstrap.Tooltip.getInstance('#example') // Returns a Bootstrap tooltip instance

// setContent example
tooltip.setContent({ '.tooltip-inner': 'another title' })
Njirayi setContentimavomereza objectmkangano, pomwe fungulo lililonse la katundu ndilosankha bwino stringmkati mwa template ya popover, ndipo mtengo uliwonse wokhudzana ndi katundu ukhoza kukhala string| element| | function| | null

Zochitika

Chochitika Kufotokozera
hide.bs.tooltip Chochitika ichi chimachotsedwa nthawi yomweyo pamene hidenjira yachitsanzo yayitanidwa.
hidden.bs.tooltip Chochitikachi chimachotsedwa pamene popover yatha kubisidwa kwa wogwiritsa ntchito (idikirira kuti kusintha kwa CSS kumalize).
inserted.bs.tooltip Chochitikachi chimachotsedwa pambuyo pa show.bs.tooltipchochitikacho pamene template ya tooltip yawonjezeredwa ku DOM.
show.bs.tooltip Chochitika ichi chimayaka nthawi yomweyo shownjira yachitsanzo itayitanidwa.
shown.bs.tooltip Chochitikachi chimachotsedwa pamene popover yawonetsedwa kwa wogwiritsa ntchito (idzadikirira kuti kusintha kwa CSS kumalize).
const myTooltipEl = document.getElementById('myTooltip')
const tooltip = bootstrap.Tooltip.getOrCreateInstance(myTooltipEl)

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

tooltip.hide()