Pitani kuzinthu zazikulu Pitani kumayendedwe adocs
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 chipani chachitatu Popper kuti ikhazikike. Muyenera kuphatikiza popper.min.js pamaso pa bootstrap.js kapena gwiritsani ntchito bootstrap.bundle.min.js/ bootstrap.bundle.jsyomwe ili ndi Popper kuti zida zigwire ntchito!
  • 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.
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 .

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

Chitsanzo: Yambitsani zida kulikonse

Njira imodzi yokhazikitsira zida zonse patsamba ingakhale yosankha malinga ndi zomwe ali nazo data-bs-toggle:

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

Zitsanzo

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.

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

Ndipo ndi HTML yachizolowezi yowonjezedwa:

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

Ndi SVG:

Sass

Zosintha

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

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:

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

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

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

Zosankha

Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-bs-, monga mu data-bs-animation="". Onetsetsani kuti musinthe mtundu wamtundu wa zosankha kuchokera ku camelCase kupita ku kebab-case podutsa zosankha kudzera pa data. Mwachitsanzo, m'malo mogwiritsa data-bs-customClass="beautifier"ntchito data-bs-custom-class="beautifier".

Dziwani kuti pazifukwa zachitetezo sanitize, sanitizeFn, ndi allowListzosankha sizingaperekedwe pogwiritsa ntchito mawonekedwe a data.
Dzina Mtundu Zosasintha Kufotokozera
animation boolean true Ikani kusintha kwa CSS pazida
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.

delay nambala | chinthu 0

Kuchedwa kusonyeza ndi kubisa chida (ms) - sikugwira ntchito pamanja choyambitsa

Ngati nambala yaperekedwa, kuchedwetsa kumayikidwa pazithunzi zonse ziwiri

Kapangidwe kachinthu ndi:delay: { "show": 500, "hide": 100 }

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.

placement chingwe | ntchito 'top'

Momwe mungayikitsire chida - auto | pamwamba | pansi | kumanzere | kulondola.
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.

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 izi ndi chitsanzo chodziwitsa .
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, idzayitanidwa ndi thiszolemba zake ku chinthu chomwe chida cholumikizidwa nacho.

trigger chingwe 'hover focus'

Momwe chida chimayambira - dinani | kugwa | kuganizira | buku. Mutha kudutsa zoyambitsa zambiri; alekanitse iwo ndi danga.

'manual'zikuwonetsa kuti chidacho chidzayambika mwadongosolo kudzera mu .show(), .hide()ndi .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.

fallbackPlacements gulu ['top', 'right', 'bottom', 'left'] Tanthauzirani malo obwerera m'mbuyo popereka mndandanda wamayikidwe angapo (molingana ndi zokonda). Kuti mumve zambiri onani zolemba za Popper's behaviour
boundary chingwe | chinthu 'clippingParents' Malire oletsa kusefukira a chida (zimagwira ntchito pa Popper's preventOverflow modifier). Mwachikhazikitso ndi 'clippingParents'ndipo imatha kuvomereza HTMLElement reference (kudzera JavaScript kokha). Kuti mudziwe zambiri onani zolemba za Popper's detectOverflow .
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.

sanitize boolean true Yambitsani kapena kuletsa ukhondo. Ngati adamulowetsa 'template'ndi 'title'options adzakhala sanitized. Onani gawo la sanitizer muzolemba zathu za JavaScript .
allowList chinthu Mtengo wofikira Chinthu chomwe chili ndi zovomerezeka ndi ma tag
sanitizeFn null | ntchito null Apa mutha kupereka ntchito yanu ya sanitize. Izi zitha kukhala zothandiza ngati mukufuna kugwiritsa ntchito laibulale yodzipatulira kuchita ukhondo.
offset gulu | chingwe | ntchito [0, 0]

Kuchotsera kwa chida chogwirizana ndi chandamale chake. Mutha kudutsa zingwe zama data zomwe zili 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, distance]

Kuti mumve zambiri onani za Popper's offset docs .

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.

Mawonekedwe a data pazida zapayekha

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

Kugwiritsa ntchito ndipopperConfig

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

chiwonetsero

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.

tooltip.show()

kubisa

Imabisa chida cha chinthu. Imabwerera kwa woyimbirayo chida chisanabisike (ie zisanachitike hidden.bs.tooltip). Izi zimatengedwa ngati "kuyambitsa" kwa chida chothandizira.

tooltip.hide()

kusintha

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.

tooltip.toggle()

kutaya

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.

tooltip.dispose()

athe

Imapatsa chida cha chinthu kuti chiwonetsedwe. Zothandizira zimayatsidwa mwachisawawa.

tooltip.enable()

letsa

Imachotsa kuthekera kwa chida cha chinthu kuti chiwonetsedwe. Zidazi zitha kuwonetsedwa pokhapokha zitayatsidwanso.

tooltip.disable()

toggleEnabled

Imasintha kuthekera kwa chida cha chinthu kuti chiwonetsedwe kapena kubisika.

tooltip.toggleEnabled()

sinthani

Imakonzanso pomwe pali chida cha chinthu.

tooltip.update()

getInstance

Njira yosasunthika yomwe imakupatsani mwayi wopeza chida cholumikizidwa ndi chinthu cha DOM

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

GetOrCreateInstance

Njira yosasunthika yomwe imakupatsani mwayi wopeza chida cholumikizidwa ndi chinthu cha DOM, kapena pangani china china ngati sichinayambike.

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

Zochitika

Mtundu wa chochitika Kufotokozera
show.bs.tooltip Chochitika ichi chimayaka nthawi yomweyo shownjira yachitsanzo itayitanidwa.
shown.bs.tooltip Chochitikachi chimachotsedwa pamene chida chawonekera kwa wogwiritsa ntchito (chidikira kuti kusintha kwa CSS kumalize).
hide.bs.tooltip Chochitika ichi chimachotsedwa nthawi yomweyo pamene hidenjira yachitsanzo yayitanidwa.
hidden.bs.tooltip Chochitikachi chimachotsedwa pamene chida chatha kubisidwa kwa wogwiritsa ntchito (chidikira kuti kusintha kwa CSS kumalize).
inserted.bs.tooltip Chochitikachi chimachotsedwa pambuyo pa show.bs.tooltipchochitikacho pamene template ya tooltip yawonjezeredwa ku DOM.
var myTooltipEl = document.getElementById('myTooltip')
var tooltip = new bootstrap.Tooltip(myTooltipEl)

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

tooltip.hide()