Popovers
Zolemba ndi zitsanzo zowonjezerera ma popover a Bootstrap, monga omwe amapezeka mu iOS, pazinthu zilizonse patsamba lanu.
Mwachidule
Zomwe muyenera kudziwa mukamagwiritsa ntchito pulogalamu ya popover:
- Popovers amadalira laibulale ya chipani chachitatu Popper kuti akhazikike. Muyenera kuphatikiza popper.min.js pamaso pa bootstrap.js kapena gwiritsani ntchito
bootstrap.bundle.min.js
/bootstrap.bundle.js
yomwe ili ndi Popper kuti popovers agwire ntchito! - Popovers amafuna chida chowonjezera ngati chodalira.
- Ma Popover amasankha kulowa pazifukwa zogwirira ntchito, chifukwa chake muyenera kuziyambitsa nokha .
- Ziro-utali
title
ndicontent
zikhalidwe sizidzawonetsa popover. - Nenani
container: 'body'
kuti mupewe kupereka zovuta muzinthu zovuta kwambiri (monga magulu athu olowetsa, magulu a batani, ndi zina). - Kuyambitsa popover pazinthu zobisika sikungagwire ntchito.
- Popovers
.disabled
kapenadisabled
zinthu ziyenera kuyambitsidwa pa chinthu chomangira. - Zikayambidwa kuchokera ku anangula omwe amazungulira mizere ingapo, ma popovers amakhala pakati pa nangula wonsewo. Gwiritsani
.text-nowrap
ntchito zanu<a>
kuti mupewe izi. - Popovers ayenera kubisidwa zinthu zawo zofananira zisanachotsedwe mu DOM.
- Popovers amatha kuyambika chifukwa cha chinthu chomwe chili mkati mwa mthunzi wa DOM.
prefers-reduced-motion
funso la media. Onani gawo
lochepetsedwa la zolemba zathu zofikira .
Pitilizani kuwerenga kuti muwone momwe popover amagwirira ntchito ndi zitsanzo zina.
Chitsanzo: Atseguleni popoposera paliponse
Njira imodzi yokhazikitsira ma popovers onse patsamba ingakhale kuwasankha mwamakhalidwe awo data-bs-toggle
:
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
Chitsanzo: Kugwiritsa ntchito container
njira
Mukakhala ndi masitaelo pa chinthu cha makolo chomwe chimasokoneza popover, mudzafuna kufotokoza mwambo container
kuti HTML ya popover iwonekere mkati mwa chinthucho.
var popover = new bootstrap.Popover(document.querySelector('.example-popover'), {
container: 'body'
})
Chitsanzo
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
Njira zinayi
Zosankha zinayi zilipo: pamwamba, kumanja, pansi, ndi kumanzere. Mayendedwe amawonekera mukamagwiritsa ntchito Bootstrap mu RTL.
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Top popover">
Popover on top
</button>
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="right" data-bs-content="Right popover">
Popover on right
</button>
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-content="Bottom popover">
Popover on bottom
</button>
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="left" data-bs-content="Left popover">
Popover on left
</button>
Chotsani mukadina kwina
Gwiritsani ntchito focus
choyambitsacho kuti muchotse zotulukapo pakadina kotsatira kwa wogwiritsa wa chinthu china kusiyana ndi chinthu chosinthira.
Chizindikiro china chofunikira pakuchotsa-pa-kudina-kotsatira
Kuti mugwiritse ntchito msakatuli woyenera komanso papulatifomu, muyenera kugwiritsa ntchito tag <a>
, osati<button>
tag, komanso muyenera kuphatikizanso mawonekedwe tabindex
.
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
var popover = new bootstrap.Popover(document.querySelector('.popover-dismiss'), {
trigger: 'focus'
})
Zinthu zolemala
Zinthu zomwe zili ndi mawonekedwe disabled
ake sizimalumikizana, kutanthauza kuti ogwiritsa ntchito sangasunthe kapena kuzidina kuti ayambitse popover (kapena chida). Monga njira yogwirira ntchito, mudzafuna kuyambitsa popover kuchokera pa chokulunga <div>
kapena <span>
, chopangidwa kuti chikhale chokhazikika pogwiritsa ntchito tabindex="0"
.
Pazinthu zoyambitsa popover zolemala, mungakondenso data-bs-trigger="hover focus"
kuti popover iwoneke ngati malingaliro apompopompo kwa ogwiritsa ntchito anu chifukwa sangayembekezere kudina chinthu cholemala.
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-content="Disabled popover">
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
</span>
Sass
Zosintha
$popover-font-size: $font-size-sm;
$popover-bg: $white;
$popover-max-width: 276px;
$popover-border-width: $border-width;
$popover-border-color: rgba($black, .2);
$popover-border-radius: $border-radius-lg;
$popover-inner-border-radius: subtract($popover-border-radius, $popover-border-width);
$popover-box-shadow: $box-shadow;
$popover-header-bg: shade-color($popover-bg, 6%);
$popover-header-color: $headings-color;
$popover-header-padding-y: .5rem;
$popover-header-padding-x: $spacer;
$popover-body-color: $body-color;
$popover-body-padding-y: $spacer;
$popover-body-padding-x: $spacer;
$popover-arrow-width: 1rem;
$popover-arrow-height: .5rem;
$popover-arrow-color: $popover-bg;
$popover-arrow-outer-color: fade-in($popover-border-color, .05);
Kugwiritsa ntchito
Yambitsani popover kudzera pa JavaScript:
var exampleEl = document.getElementById('example')
var popover = new bootstrap.Popover(exampleEl, options)
Kupanga ma popover ntchito kwa ogwiritsa ntchito kiyibodi ndi ukadaulo wothandizira
Kuti mulole ogwiritsa ntchito kiyibodi kuti ayambitse ma popovers anu, muyenera kungowonjezera kuzinthu za HTML zomwe nthawi zambiri zimakhala zokhazikika komanso zolumikizana (monga maulalo kapena zowongolera mawonekedwe). Ngakhale zinthu zosasinthika za HTML (monga <span>
s) zitha kukhala zowoneka bwino powonjezera mawonekedwe tabindex="0"
, izi ziwonjezera zoyimitsa zosokoneza komanso zosokoneza pazinthu zomwe sizimalumikizana ndi ogwiritsa ntchito kiyibodi, ndipo matekinoloje othandizira ambiri pakadali pano salengeza zomwe zili mu popover pakadali pano. . Kuphatikiza apo, musadalire kokha hover
ngati choyambitsa ma popover anu, chifukwa izi zipangitsa kuti zikhale zosatheka kuyambitsa ogwiritsa ntchito kiyibodi.
Ngakhale mutha kuyika ma HTML olemera, opangidwa ndi ma popover ndi html
mwayi, tikupangira kuti mupewe kuwonjezera kuchuluka kwazinthu. Momwe ma popovers amagwirira ntchito pano ndikuti, zikawonetsedwa, zomwe zili ndizomwe zimalumikizidwa ndi zomwe aria-describedby
zimayambitsa. Zotsatira zake, zonse zomwe zili mu popover zidzalengezedwa kwa ogwiritsa ntchito ukadaulo wothandizira ngati mtsinje wautali wosasokonezeka.
Kuphatikiza apo, ngakhale ndikothekanso kuphatikiza zowongolera (monga mawonekedwe amtundu kapena maulalo) mu popover yanu (powonjezera zinthuzi pazovomerezeka allowList
ndi ma tag), dziwani kuti pakadali pano popover samayang'anira dongosolo la kiyibodi. Wogwiritsa ntchito kiyibodi akatsegula popover, kuyang'ana kumakhalabe pazomwe zikuyambitsa, ndipo monga momwe popover nthawi zambiri samatsata choyambitsacho pamapangidwe a chikalatacho, palibe chitsimikizo kuti kupita patsogolo / kukanikiza.TABidzasuntha wogwiritsa ntchito kiyibodi mu popover yokha. Mwachidule, kungowonjezera maulamuliro olumikizana ku popover kungapangitse zowongolerazi kukhala zosafikirika/zosagwiritsidwa ntchito kwa ogwiritsa ntchito kiyibodi ndi ogwiritsa ntchito matekinoloje othandizira, kapena kupanga dongosolo losamveka bwino. Muzochitika izi, lingalirani kugwiritsa ntchito dialog ya modal m'malo mwake.
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"
.
sanitize
,
sanitizeFn
, ndi
allowList
zosankha sizingaperekedwe pogwiritsa ntchito mawonekedwe a data.
Dzina | Mtundu | Zosasintha | Kufotokozera |
---|---|---|---|
animation |
boolean | true |
Ikani kusintha kwa CSS fade ku popover |
container |
chingwe | chinthu | zabodza | false |
Imawonjezera popover ku chinthu china. Chitsanzo: |
content |
chingwe | chinthu | ntchito | '' |
Chitsimikizo cha zinthu ngati Ngati ntchito yaperekedwa, |
delay |
nambala | chinthu | 0 |
Kuchedwa kusonyeza ndi kubisa popover (ms) - sikugwira ntchito pamanja choyambitsa mtundu Ngati nambala yaperekedwa, kuchedwetsa kumayikidwa pazithunzi zonse ziwiri Kapangidwe kachinthu ndi: |
html |
boolean | false |
Ikani HTML mu popover. Ngati zabodza, innerText katundu adzagwiritsidwa ntchito kuyika zomwe zili mu DOM. Gwiritsani ntchito mawu ngati mukuda nkhawa ndi kuukira kwa XSS. |
placement |
chingwe | ntchito | 'right' |
Momwe mungayikitsire popover - auto | pamwamba | pansi | kumanzere | kulondola. Ntchito ikagwiritsidwa ntchito kudziwa malo, imatchedwa ndi popover DOM node ngati mkangano wake woyamba komanso chinthu choyambitsa DOM node ngati yachiwiri. Nkhaniyi |
selector |
chingwe | zabodza | false |
Ngati chosankha chaperekedwa, zinthu za popover zidzaperekedwa ku zomwe zafotokozedwazo. M'malo mwake, izi zimagwiritsidwa ntchito kuti zithandizire HTML zomwe zili ndi ma popover awonjezedwe. Onani izi ndi chitsanzo chodziwitsa . |
template |
chingwe | '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>' |
Base HTML kuti mugwiritse ntchito popanga popover. Ma popover adzabayidwa Ma popover adzabayidwa
Chokulunga chakunja chiyenera kukhala ndi |
title |
chingwe | chinthu | ntchito | '' |
Mtengo wamutu wotsikirapo ngati Ngati ntchito yaperekedwa, |
trigger |
chingwe | 'click' |
Momwe popover imayambira - dinani | kugwa | kuganizira | buku. Mutha kudutsa zoyambitsa zambiri; alekanitse iwo ndi danga. manual sichingaphatikizidwe ndi choyambitsa china chilichonse. |
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 popover (amangokhudza 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 ku popover ikawonetsedwa. 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. |
sanitize |
boolean | true |
Yambitsani kapena kuletsa ukhondo. Ngati adamulowetsa 'template' , 'content' ndipo 'title' zosankha zidzayeretsedwa. 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, 8] |
Kuchepetsa kwa popover mogwirizana ndi cholinga chake. Mutha kudutsa zingwe zama data zomwe zili ndi ma comma olekanitsidwa monga: 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: . 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 pamapopovers apawokha
Zosankha za popovers pawokha zitha kufotokozedwa mwanjira ina pogwiritsa ntchito mawonekedwe a data, monga tafotokozera pamwambapa.
Kugwiritsa ntchito ndipopperConfig
var popover = new bootstrap.Popover(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 .
chiwonetsero
Imawulula kuchuluka kwa zinthu. Imabwereranso kwa woyimba foniyo isanawonetsedwe (ie zisanachitike shown.bs.popover
). Izi zimaganiziridwa kuti ndi "zamanja" zoyambitsa popover. Ma Popovers omwe mutu wawo ndi zomwe zili muutali wa ziro sizimawonetsedwa.
myPopover.show()
kubisa
Imabisa kuchuluka kwa zinthu. Imabwereranso kwa woyimba foniyo isanabisike (ie zisanachitike hidden.bs.popover
). Izi zimaganiziridwa kuti ndi "zamanja" zoyambitsa popover.
myPopover.hide()
kusintha
Imasintha kuphulika kwa chinthu. Imabwereranso kwa woyimba foniyo isanawonetsedwe kapena kubisidwa (ie zisanachitike shown.bs.popover
kapena hidden.bs.popover
chochitikacho). Izi zimaganiziridwa kuti ndi "zamanja" zoyambitsa popover.
myPopover.toggle()
kutaya
Imabisa ndikuwononga popover ya chinthu (Imachotsa zosungidwa pa chinthu cha DOM). Ma Popovers omwe amagwiritsa ntchito kugawira ena (omwe amapangidwa pogwiritsa ntchito selector
mwayi ) sangawonongedwe paokha pazoyambitsa zoyambitsa.
myPopover.dispose()
athe
Zimapereka mwayi wowoneka bwino wa element. Popovers amayatsidwa mwachisawawa.
myPopover.enable()
letsa
Imachotsa kuthekera kwa popover ya chinthu kuti iwonetsedwe. Popover imatha kuwonetsedwa ngati iyatsidwanso.
myPopover.disable()
toggleEnabled
Imasintha kuthekera kwa kufalikira kwa chinthu kuti chiwoneke kapena kubisika.
myPopover.toggleEnabled()
sinthani
Imasinthiratu pomwe zinthu zachuluka.
myPopover.update()
getInstance
Njira yosasunthika yomwe imakupatsani mwayi wopeza mawonekedwe a popover olumikizidwa ndi chinthu cha DOM
var exampleTriggerEl = document.getElementById('example')
var popover = bootstrap.Popover.getInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
GetOrCreateInstance
Njira yosasunthika yomwe imakupatsani mwayi wopeza mawonekedwe a popover olumikizidwa ndi chinthu cha DOM, kapena pangani china china ngati sichinayambike.
var exampleTriggerEl = document.getElementById('example')
var popover = bootstrap.Popover.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
Zochitika
Mtundu wa chochitika | Kufotokozera |
---|---|
onetsani.bs.popover | Chochitika ichi chimayaka nthawi yomweyo show njira yachitsanzo itayitanidwa. |
zowonetsedwa.bs.popover | Chochitikachi chimachotsedwa pamene popover yawonetsedwa kwa wogwiritsa ntchito (idzadikirira kuti kusintha kwa CSS kumalize). |
bisani.bs.popover | Chochitika ichi chimachotsedwa nthawi yomweyo pamene hide njira yachitsanzo yayitanidwa. |
zobisika.bs.popover | Chochitikachi chimachotsedwa pamene popover yatha kubisidwa kwa wogwiritsa ntchito (idikirira kuti kusintha kwa CSS kumalize). |
anaika.bs.popover | Chochitikachi chimachotsedwa pambuyo pa show.bs.popover chochitikacho pamene template ya popover yawonjezedwa ku DOM. |
var myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
// do something...
})