Tsibela kumxholo ophambili Tsiba uye kukhangelo lwamaxwebhu
in English

Iipopovers

Amaxwebhu kunye nemizekelo yokongezwa kweBootstrap poppovers, njengaleyo ifumaneka kwi-iOS, kuyo nayiphi na into ekwisiza sakho.

Isishwankathelo

Izinto omawuzazi xa usebenzisa iplagi yepopover:

  • Abantu abadumileyo baxhomekeke kwithala leencwadi lesithathu lePopper ngokubekwa . Kufuneka ubandakanye i -popper.min.js phambi kwe-bootstrap.js okanye usebenzise bootstrap.bundle.min.js/ bootstrap.bundle.jsequlethe iPopper ukuze i-popovers isebenze!
  • IiPopovers zifuna iplagi yesixhobo njengesixhobo sokuxhomekeka.
  • IiPopovers zingenile ngenxa yezizathu zokusebenza, ke kufuneka uziqalise ngokwakho .
  • Ubude obuziro titlekunye contentnamaxabiso asoze abonise ipopover.
  • Cacisa container: 'body'ukunqanda unikezelo lweengxaki kumacandelo antsokothileyo (njengamaqela ethu egalelo, amaqela amaqhosha, njl.njl).
  • Ukuxhokonxa iipopovers kwizinto ezifihlakeleyo aziyi kusebenza.
  • Iipopovers ze .disabledokanye ielementi kufuneka zivuswe kwinto esongelwayo disabled.
  • Xa isenziwa ukusuka kwii-ankile ezisonga kwimigca emininzi, iipopovers ziya kugxininiswa phakathi kobubanzi beankile ngokubanzi. Sebenzisa .text-nowrapkwi yakho <a>ukunqanda le ukuziphatha.
  • Iipopovers mazifihlwe phambi kokuba izinto ezihambelanayo zisuswe kwiDOM.
  • Iipopovers zinokuvuswa enkosi kwinto engaphakathi kwesithunzi se-DOM.
Ngokungagqibekanga, eli candelo lisebenzisa isicoci esakhelwe ngaphakathi somxholo, esihluba naziphi na izinto zeHTML ezingavumelekanga ngokucacileyo. Bona icandelo lesanitizer kuxwebhu lwethu lweJavaScript ngeenkcukacha ezithe vetshe.
Isiphumo soopopayi seli candelo sixhomekeke prefers-reduced-motionkumbuzo wemidiya. Jonga icandelo leentshukumo ezincitshisiweyo kuxwebhu lwethu lofikelelo .

Qhubeka ufunda ukuze ubone indlela iipopovers ezisebenza ngayo neminye imizekelo.

Umzekelo: Vumela iipopovers kuyo yonke indawo

Enye indlela yokuqalisa zonke iipopovers kwiphepha inokuba kukukhetha ngophawu lwazo data-bs-toggle:

var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
  return new bootstrap.Popover(popoverTriggerEl)
})

Umzekelo: Ukusebenzisa containerukhetho

Xa unezinye izimbo kwinto yomzali ephazamisana ne-popover, uya kufuna ukukhankanya isiko containerukuze i-HTML ye-popover ivele ngaphakathi kweso siqalelo endaweni yoko.

var popover = new bootstrap.Popover(document.querySelector('.example-popover'), {
  container: 'body'
})

Umzekelo

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

Iindlela ezine

Zine iinketho ezikhoyo: phezulu, ekunene, ezantsi, nasekhohlo zilungelelanisiwe. Izalathiso ziboniswa xa usebenzisa i-Bootstrap kwi-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>

Lahla ngokucofa okulandelayo

Sebenzisa i- focustrigger ukugxotha iipopovers kunqakrazo olulandelayo lomsebenzisi lwento eyahlukileyo kunento yokuguqula.

Uphawulo oluthile luyafuneka ukuze ugxothe-ngokucofa-okulandelayo

Kwibrowser echanekileyo kunye nokuziphatha kweqonga, kufuneka usebenzise <a>ithegi, hayi ithegi , <button>kwaye kufuneka uquke tabindexuphawu loyelelwano.

<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'
})

Izinto ezikhubazekileyo

Izinto disabledezinophawu azisebenzi, oku kuthetha ukuba abasebenzisi abanako ukushukuma okanye ukucofa ukuze baqalise ipopover (okanye inqaku lesixhobo). Njengomsebenzi wokusebenza, uya kufuna ukwenza i-popover isuka kwisisonga <div>okanye <span>, yenziwe ngokufanelekileyo ikhibhodi-ijolise ekusebenziseni tabindex="0".

Kwiziphembeleli ze-popover ezikhubazekileyo, unokukhetha kwakhona data-bs-trigger="hover focus"ukuze i-popover ibonakale njengengxelo ebonwayo kwangoko kubasebenzisi bakho njengoko bengenakulindela ukucofa into ekhubazekileyo.

<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

Izinto eziguquguqukayo

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

Ukusetyenziswa

Vumela iipopovers ngeJavaScript:

var exampleEl = document.getElementById('example')
var popover = new bootstrap.Popover(exampleEl, options)

Ukwenza iipopovers zisebenzele ikhibhodi kunye nabasebenzisi betekhnoloji abancedisayo

Ukuvumela abasebenzisi bebhodi yezitshixo ukuba bavule iipopovers zakho, kufuneka ubongeze kuphela kwizinto ze-HTML eziqhelekileyo ezijolise kwikhibhodi kwaye ziyasebenzisana (ezifana namakhonkco okanye ulawulo lwefom). Nangona izinto ze-HTML ezingenamkhethe (ezinje <span>s) zinokwenziwa ziqwalaselwe ngokongeza tabindex="0"uphawu, oku kuyakongeza ukumisa okunokucaphukisa kunye nokubhidanisa ithebhu kwizinto ezingasebenzisaniyo kubasebenzisi bebhodi yezitshixo, kwaye uninzi lweetekhnoloji ezincedisayo okwangoku azibhengezi umxholo we popover kule meko. . Ukongeza, ungathembeli kuphela hovernjengesixhobo se-popovers zakho, njengoko oku kuya kubenza bangakwazi ukuqalisa abasebenzisi bebhodi yezitshixo.

Ngelixa unokufaka i-HTML etyebileyo, ecwangcisiweyo kwiipopovers kunye htmlnokhetho, sicebisa ngamandla ukuba ukunqande ukongeza umthamo ogqithisileyo womxholo. Indlela i-popovers esebenza ngayo ngoku yeyokuba, xa sele ibonisiwe, umxholo wabo ubotshelelwe kwinto yokuqalisa kunye aria-describedbynophawu. Ngenxa yoko, yonke imixholo ye-popover iya kubhengezwa kubasebenzisi betekhnoloji abancedisayo njengomjelo omde, ongaphazanyiswa.

Ukongeza, ngelixa kunokwenzeka ukubandakanya ulawulo olusebenzisanayo (olufana nezinto zefom okanye amakhonkco) kwi-popover yakho (ngokongeza ezi zinto kwiimpawu allowListezivumelekileyo kunye neethegi), qaphela ukuba okwangoku i-popover ayilulawuli ucwangco lwe-keyboard. Xa umsebenzisi webhodi yezitshixo evula i-popover, ingqwalasela ihlala kwi-triggering element, kwaye njengoko i-popover idla ngokungalandeli ngokukhawuleza i-trigger kwisakhiwo soxwebhu, akukho siqinisekiso sokuba ukuya phambili / ukucinezela.TABizakuhambisa umsebenzisi webhodi yezitshixo kwi popover ngokwayo. Ngokufutshane, ukongeza ngokulula izilawuli ezisebenzisanayo kwi-popover kunokwenza olu lawulo lufikeleleke/ lungasebenziseki kubasebenzisi bebhodi yezitshixo kunye nabasebenzisi betekhnoloji encedisayo, okanye ubuncinci yenzela ulungelelwaniso lokugxila ngokubanzi olungekho ngqiqweni. Kwezi meko, cinga ukusebenzisa incoko yababini yemodal endaweni yoko.

Iinketho

Iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript. Kuphawu lwedatha, faka igama lokhetho ku data-bs-, njengakwi data-bs-animation="". Qinisekisa ukuba utshintsha uhlobo lwetyala legama lokukhetha ukusuka kwikamela ukuya kwi-kebab-case xa udlula iinketho ngeempawu zedatha. Umzekelo, endaweni yokusebenzisa data-bs-customClass="beautifier", sebenzisa data-bs-custom-class="beautifier".

Qaphela ukuba ngenxa yezizathu zokhuseleko i sanitize, sanitizeFn, kunye allowListneenketho azikwazi kunikezelwa kusetyenziswa iimpawu zedata.
Igama Uhlobo Ukuhlala kukho Inkcazo
animation boolean true Faka inguqu ye-CSS fade kwi-popover
container umtya | into | bubuxoki false

Ifakela ipopover kwinto ethile. Umzekelo: container: 'body'. Olu khetho luluncedo kakhulu kuba lukuvumela ukuba ubeke ipopover ekuhambeni koxwebhu kufutshane nesiqalo - esizakunqanda i popover ekudadandeni kude nesiqalo ngexesha lefestile.

content umtya | into | umsebenzi ''

Ixabiso lomxholo data-bs-contentelihlala likhona ukuba uphawu loyelelwano alukho.

Ukuba umsebenzi unikiwe, uya kubizwa ngokuba thisnereferensi iseti kwinto edityaniswe nepopover.

delay inombolo | into 0

Ukulibazisa ukubonisa kunye nokufihla i-popover (ms) - ayisebenzi kuhlobo lwe-trigger ye-manual

Ukuba inani linikiwe, ukulibaziseka kufakwa kuzo zombini ezifihla/umboniso

Ulwakhiwo lwento yile:delay: { "show": 500, "hide": 100 }

html boolean false Faka i-HTML kwi-popover. Ukuba asiyonyani, innerTextipropathi iya kusetyenziswa ukufaka umxholo kwiDOM. Sebenzisa umbhalo ukuba unexhala malunga nohlaselo lwe-XSS.
placement umtya | umsebenzi 'right'

Indlela yokubeka ipopover - auto | phezulu | emazantsi | ekhohlo | kunene.
Xa autoikhankanyiwe, izakuphinda ihlengahlengise i popover.

Xa umsebenzi usetyenziswa ukumisela indawo, ibizwa ngokuba yi-popover node ye-DOM njengengxoxo yayo yokuqala kunye nesiqalo se-DOM node njengesibini sayo. Umxholo thisumiselwe kumzekelo we popover.

selector umtya | bubuxoki false Ukuba umkhethi unikiwe, izinto ze popover ziya kunikezelwa kwiithagethi ezichaziweyo. Ngokwesiqhelo, oku kusetyenziselwa ukwenza umxholo weHTML oguquguqukayo ube neepopovers zongezwe. Bona oku kunye nomzekelo ofundisayo .
template umtya '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'

Isiseko se-HTML esinokusetyenziswa xa usenza ipopover.

I-popover's titleiya kugalelwa kwi- .popover-header.

I-popover's contentiya kugalelwa kwi- .popover-body.

.popover-arrowiya kuba lutolo lwe popover.

Isiqalelo sokusonga sangaphandle kufuneka sibe .popoverneklasi.

title umtya | into | umsebenzi ''

Ixabiso lesihloko esihlala sihleli ukuba titleuphawu loyelelwano alukho.

Ukuba umsebenzi unikiwe, uya kubizwa ngokuba thisnereferensi iseti kwinto edityaniswe nepopover.

trigger umtya 'click' Ivuswa njani ipopover - cofa | jonga | gxila | incwadi yesandla. Unokudlula izichukumisi ezininzi; bahlule ngesithuba. manualayinakudityaniswa naso nasiphi na esinye isiqhushumbisi.
fallbackPlacements uluhlu ['top', 'right', 'bottom', 'left'] Chaza ukubekelwa umva ngokubonelela ngoluhlu lweendawo ezibekwe kuluhlu (ngolandelelwano olukhethwayo). Ngolwazi oluthe vetshe jonga kumaxwebhu okuziphatha kaPopper
boundary umtya | isiqalelo 'clippingParents' Umda wothintelo lokuphuphumala kwe-popover (usebenza kuphela kwisilungisi sePopper sokuthintela ukuphuphuma). Ngokungagqibekanga yiyo 'clippingParents'kwaye inokwamkela i-HTMLElement ireferensi (ngeJavaScript kuphela). Ngolwazi oluthe vetshe jonga kuPopper's detectOverflow amaxwebhu .
customClass umtya | umsebenzi ''

Yongeza iiklasi kwi-popover xa ibonisiwe. Qaphela ukuba ezi klasi ziya kongezwa ukongeza kuzo naziphi na iiklasi ezichazwe kwithempleyithi. Ukongeza iiklasi ezininzi, zahlule ngezithuba: 'class-1 class-2'.

Ungaphinda ugqithise umsebenzi ozakubuyisela umtya omnye oqulathe amagama odidi olongezelelweyo.

sanitize boolean true Yenza okanye uvale ucoceko. Ukuba ivuliwe 'template', 'content'kwaye 'title'iinketho ziyakuhlanjululwa. Jonga icandelo lesicoci kuxwebhu lwethu lweJavaScript .
allowList into Ixabiso elimiselweyo Into equlathe iimpawu ezivumelekileyo kunye neethegi
sanitizeFn null | umsebenzi null Apha ungabonelela ngomsebenzi wakho wokucoca. Oku kunokuba luncedo ukuba ukhetha ukusebenzisa ithala leencwadi elizinikeleyo ukwenza ucoceko.
offset uluhlu | umtya | umsebenzi [0, 8]

I-Offset ye-popover ngokumalunga nokujoliswe kuyo. Ungadlula umtya kwiimpawu zedatha ezinamaxabiso ahlulwe ngokwekoma afana:data-bs-offset="10,20"

Xa umsebenzi usetyenziselwa ukumisela i-offset, ibizwa ngento equlethe i-popper placement, ireferensi, kunye ne-popper rects njengengxabano yayo yokuqala. Isiqalo se-DOM node sigqithiselwe njengengxoxo yesibini. Umsebenzi kufuneka ubuyisele uluhlu olunamanani amabini:[skidding, distance] .

Ngolwazi oluthe vetshe jonga kumaxwebhu e-Popper's offset .

popperConfig null | into | umsebenzi null

Ukutshintsha uqwalaselo lwePopper lweBootstrap olungagqibekanga, bona uqwalaselo lwePopper .

Xa umsebenzi usetyenziswa ukwenza uqwalaselo lwePopper, ibizwa ngento equlathe uqwalaselo lwePopper yeBootstrap engagqibekanga. Ikunceda ukuba usebenzise kwaye udibanise ukungagqibeki kunye noqwalaselo lwakho. Umsebenzi kufuneka ubuyisele into yoqwalaselo yePopper.

Iimpawu zedatha yepopovers nganye

Ukhetho lwepopovers nganye lunokuchazwa ngokusetyenziswa kweempawu zedatha, njengoko kucacisiwe ngasentla.

Ukusebenzisa umsebenzi ngepopperConfig

var popover = new bootstrap.Popover(element, {
  popperConfig: function (defaultBsPopperConfig) {
    // var newPopperConfig = {...}
    // use defaultBsPopperConfig if needed...
    // return newPopperConfig
  }
})

Iindlela

Iindlela ze-Asynchronous kunye notshintsho

Zonke iindlela ze-API zi -asynchronous kwaye ziqala utshintsho . Babuyela kumnxeba ngokukhawuleza nje ukuba utshintsho luqalisiwe kodwa ngaphambi kokuba luphele . Ukongeza, umnxeba wendlela kwicandelo lotshintsho awuyi kuhoywa .

Jonga uxwebhu lwethu lweJavaScript ngolwazi olungakumbi .

bonisa

Ityhila ukuvela kwento ethile. Ibuyisela kumnxeba phambi kokuba i-popover iboniswe (okt phambi kokuba shown.bs.popoverisiganeko senzeke). Oku kuthathwa njenge "manual" yokuqalisa i-popover. Iipopovers ezinesihloko kunye nomxholo wazo zombini ubude obungu-zero azizange ziboniswe.

myPopover.show()

fihla

Ifihla imvelaphi yento. Ibuyisela kumnxeba phambi kokuba i-popover ifihliwe (okt phambi kwehidden.bs.popover isiganeko senzeke). Oku kuthathwa njenge "manual" yokuqalisa i-popover.

myPopover.hide()

guqula

Itshintsha ipopover yesiqalelo. Ibuyisela kumnxeba phambi kokuba i-popover iboniswe okanye ifihliwe (okt phambi kokuba isiganeko shown.bs.popoverokanye hidden.bs.popoverisiganeko senzeke). Oku kuthathwa njenge "manual" yokuqalisa i-popover.

myPopover.toggle()

lahla

Ifihla kwaye itshabalalise i-popover yento (Isusa idatha egciniweyo kwi-DOM element). Iipopovers ezisebenzisa unikezelo (okuyilwe kusetyenziswa ukhethoselector ) azinakutshatyalaliswa zizodwa kwinzala yezinto ezibangelayo .

myPopover.dispose()

yenza

Inika i- element's popover isakhono sokuboniswa. Iipopovers zenziwe ngokuzenzekelayo.

myPopover.enable()

khubaza

Isusa isakhono se popover yesiqalelo esizakuboniswa. I-popover iya kuboniswa kuphela ukuba ivuliwe kwakhona.

myPopover.disable()

toggleEnabled

Iguqulela isakhono se-popover yesiqalelo esiboniswa okanye sifihlwe.

myPopover.toggleEnabled()

hlaziya

Ihlaziya indawo ye popover yento.

myPopover.update()

getInstance

Indlela engatshintshiyo ekuvumela ukuba ufumane umzekelo we popover onxulunyaniswa nento yeDOM

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

getOrCreateInstance

Indlela engatshintshiyo ekuvumela ukuba ufumane umzekelo we popover onxulunyaniswa nento yeDOM, okanye wenze entsha ukuba ayiqalwanga.

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

Iziganeko

Uhlobo lomsitho Inkcazo
bonisa.bs.popover Esi siganeko sivutha ngokukhawuleza xa showkubizwa indlela yomzekelo.
ibonisiwe.bs.popover Esi siganeko sigxothwa xa i-popover yenziwe yabonakala kumsebenzisi (iya kulinda iinguqu zeCSS ukuba zigqibe).
fihla.bs.popover Esi siganeko sigxothwa ngokukhawuleza xa hideindlela yomzekelo ibiziwe.
efihliweyo.bs.popover Esi siganeko sigxothwa xa i-popover igqibile ukufihlwa kumsebenzisi (iya kulinda iinguqu zeCSS ukuba zigqibe).
ifakiwe.bs.popover Esi siganeko sigxothwa emva show.bs.popoverkwesiganeko xa i-template ye-popover yongezwa kwi-DOM.
var myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
  // do something...
})