Malangizo
Zolemba ndi zitsanzo zowonjezerera zida za Bootstrap ndi CSS ndi JavaScript pogwiritsa ntchito CSS3 pa makanema ojambula pamanja ndi mawonekedwe a data posungira 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.js
yomwe ili ndi Popper kuti zida zigwire ntchito! - Ngati mukupanga JavaScript yathu kuchokera kugwero, pamafunika
util.js
. - Zida ndizolowera pazifukwa zogwirira ntchito, chifukwa chake muyenera kuziyambitsa nokha .
- Zida zokhala ndi ziro 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
.disabled
kapenadisabled
zinthu ziyenera kuyambitsidwa pa chinthu chokulunga. - Zikayambika kuchokera ku ma hyperlink omwe amatambasula mizere ingapo, nsonga za zida zimakhazikika. 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.
prefers-reduced-motion
funso 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 kuwasankha malinga ndi momwe data-toggle
alili:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
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 zingawonekere 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 malangizo anayi: pamwamba, kumanja, pansi, ndi kumanzere.
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
Tooltip on top
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="right" title="Tooltip on right">
Tooltip on right
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="Tooltip on bottom">
Tooltip on bottom
</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="left" title="Tooltip on left">
Tooltip on left
</button>
Ndipo ndi HTML yachizolowezi yowonjezedwa:
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
Tooltip with HTML
</button>
Kugwiritsa ntchito
Pulogalamu yowonjezera yowonjezera imapanga zokhutira ndi zolembera zomwe zimafunidwa, ndipo mwachisawawa zimayika zida pambuyo pa zomwe zimayambitsa.
Yambitsani chida kudzera pa JavaScript:
$('#example').tooltip(options)
Kusefukira auto
ndiscroll
Malo a Tooltip amayesa kusintha okha ngati chotengera cha makolo chili nacho overflow: auto
kapena overflow: scroll
ngati makonda athu .table-responsive
, komabe chimasunga malo omwe adayikapo. Kuti muthetse, ikani boundary
chisankho ku china chilichonse kupatula mtengo wokhazikika, 'scrollParent'
monga 'window'
:
$('#example').tooltip({ boundary: 'window' })
Markup
Cholembera chofunikira pa chida ndi mawonekedwe chabe data
ndipo title
pa chinthu cha HTML mukufuna kukhala ndi chida. Zolemba zopangira zida ndizosavuta, ngakhale zimafunikira malo (mwachisawawa, zokhazikitsidwa top
ndi pulogalamu yowonjezera).
Kupanga zida zogwirira ntchito kwa 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 hover
ngati choyambitsa chida chanu, chifukwa izi zipangitsa kuti zida zanu zikhale zosatheka kuyambitsa ogwiritsa ntchito kiyibodi.
<!-- HTML to write -->
<a href="#" data-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="arrow"></div>
<div class="tooltip-inner">
Some tooltip text!
</div>
</div>
Zinthu zolemala
Zinthu zomwe zili ndi mawonekedwe disabled
ake 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 pachimake <div>
kapena <span>
, chopangidwa kuti chikhale chokhazikika pogwiritsa ntchito kiyibodi tabindex="0"
, ndikupitilira zomwe pointer-events
zili olumala.
<span class="d-inline-block" tabindex="0" data-toggle="tooltip" title="Disabled tooltip">
<button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
</span>
Zosankha
Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-
, monga mu data-animation=""
.
sanitize
,
sanitizeFn
ndi
whiteList
zosankha sizingaperekedwe pogwiritsa ntchito mawonekedwe a data.
Dzina | Mtundu | Zosasintha | Kufotokozera |
---|---|---|---|
makanema ojambula | boolean | zoona | Ikani kusintha kwa CSS pazida |
chotengera | chingwe | chinthu | zabodza | zabodza | Imawonjezera chida ku chinthu china. Chitsanzo: |
kuchedwa | nambala | chinthu | 0 | Kuchedwa kusonyeza ndi kubisa chida (ms) - sikugwira ntchito pamanja choyambitsa Ngati nambala yaperekedwa, kuchedwetsa kumayikidwa pazithunzi zonse ziwiri Kapangidwe kachinthu ndi: |
html | boolean | zabodza | Lolani HTML pazida. Ngati ndi zoona, ma tag a HTML mu tooltip's Gwiritsani ntchito mawu ngati mukuda nkhawa ndi kuukira kwa XSS. |
kuika | chingwe | ntchito | 'pamwamba' | Momwe mungayikitsire chida - auto | pamwamba | pansi | kumanzere | kulondola. Ntchito ikagwiritsidwa ntchito kudziwa malo, imatchedwa ndi chida cha DOM node ngati mtsutso wake woyamba ndi chinthu choyambitsa DOM node ngati yachiwiri. Nkhaniyi |
wosankha | chingwe | zabodza | zabodza | 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.on thandizo). Onani izi ndi chitsanzo chodziwitsa . |
template | chingwe | '<div class="tooltip" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>' |
Base HTML kuti mugwiritse ntchito popanga chida. Ma tooltip adzabayidwa
Chovala chakunja chiyenera kukhala ndi |
mutu | chingwe | chinthu | ntchito | '' | Mtengo wamutu wotsikirapo ngati Ngati ntchito yaperekedwa, idzayitanidwa ndi |
choyambitsa | chingwe | 'hover focus' | Momwe chida chimayambira - dinani | kugwa | kuganizira | buku. Mutha kudutsa zoyambitsa zambiri; alekanitse iwo ndi danga.
|
kuchepetsa | nambala | chingwe | ntchito | 0 | Kuchotsera kwa chida chogwirizana ndi chandamale chake. Ntchito ikagwiritsidwa ntchito kuti izindikire kuchotsera, imatchedwa ndi chinthu chomwe chili ndi data ya offset ngati mkangano wake woyamba. Ntchitoyi iyenera kubweza chinthu chofanana. Choyambitsa chinthu cha DOM node chimadutsa ngati mkangano wachiwiri. Kuti mumve zambiri onani za Popper's offset docs . |
fallbackPlacement | chingwe | gulu | 'tembenuzani' | Lolani kutchula malo omwe Popper adzagwiritse ntchito pobwerera. Kuti mumve zambiri onani zolemba za Popper's behaviour |
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: Mukhozanso kupereka ntchito yomwe iyenera kubweza chingwe chimodzi chokhala ndi mayina owonjezera amagulu. |
malire | chingwe | chinthu | 'scrollParent' | Kusefukira malire malire a chida. Imavomereza mfundo za 'viewport' , 'window' , 'scrollParent' , kapena HTMLElement reference (JavaScript yokha). Kuti mudziwe zambiri onani za Popper's preventOverflow docs . |
yeretsani | boolean | zoona | Yambitsani kapena kuletsa ukhondo. Ngati adamulowetsa 'template' ndi 'title' options adzakhala sanitized. Onani gawo la sanitizer muzolemba zathu za JavaScript . |
whiteList | 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. |
popperConfig | null | chinthu | null | Kuti musinthe kasinthidwe ka Popper ka Bootstrap, onani kasinthidwe ka Popper |
Mawonekedwe a data pazida zapayekha
Zosankha za zida zapayekha zitha kufotokozedwa pogwiritsa ntchito mawonekedwe a data, monga tafotokozera pamwambapa.
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 .
$().tooltip(options)
Imangiriza chogwirizira ku zida zosonkhanitsira.
.tooltip('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.
$('#element').tooltip('show')
.tooltip('hide')
Imabisa chida cha chinthu. Imabwerera kwa woyimbirayo chida chisanabisike (ie zisanachitike hidden.bs.tooltip
). Izi zimatengedwa ngati "kuyambitsa" kwa chida chothandizira.
$('#element').tooltip('hide')
.tooltip('toggle')
Imatembenuza chida cha chinthu. Imabwerera kwa woyimbirayo chida chisanasonyezedwe kapena kubisidwa (ie chisanachitike shown.bs.tooltip
kapena hidden.bs.tooltip
chochitikacho). Izi zimatengedwa ngati "kuyambitsa" kwa chida chothandizira.
$('#element').tooltip('toggle')
.tooltip('dispose')
Imabisa ndi kuwononga chida cha chinthu. Zida zomwe zimagwiritsa ntchito kugawira ena (omwe amapangidwa pogwiritsa ntchito selector
kusankha ) sizingawonongeke pazigawo zoyambitsa mbadwa.
$('#element').tooltip('dispose')
.tooltip('enable')
Imapatsa chida cha chinthu kuti chiwonetsedwe. Zida zothandizira zimayatsidwa mwachisawawa.
$('#element').tooltip('enable')
.tooltip('disable')
Imachotsa kuthekera kwa chida cha chinthu kuti chiwonetsedwe. Zidazi zitha kuwonetsedwa pokhapokha zitayatsidwanso.
$('#element').tooltip('disable')
.tooltip('toggleEnabled')
Imasintha kuthekera kwa chida cha chinthu kuti chiwonetsedwe kapena kubisika.
$('#element').tooltip('toggleEnabled')
.tooltip('update')
Imakonzanso pomwe pali chida cha chinthu.
$('#element').tooltip('update')
Zochitika
Mtundu wa Chochitika | Kufotokozera |
---|---|
show.bs.tip | Chochitika ichi chimayaka nthawi yomweyo show njira yachitsanzo itayitanidwa. |
chiwonetsero.bs.tip | Chochitikachi chimachotsedwa pamene chida chawonekera kwa wogwiritsa ntchito (chidikira kuti kusintha kwa CSS kumalize). |
hide.bs.tip | Chochitika ichi chimachotsedwa nthawi yomweyo pamene hide njira yachitsanzo yayitanidwa. |
zobisika.bs.tip | Chochitikachi chimachotsedwa pamene chida chatha kubisidwa kwa wogwiritsa ntchito (chidikira kuti kusintha kwa CSS kumalize). |
inserted.bs.tooltip | Chochitikachi chimachotsedwa pambuyo pa show.bs.tooltip chochitikacho pamene template ya chida chawonjezeredwa ku DOM. |
$('#myTooltip').on('hidden.bs.tooltip', function () {
// do something...
})