Svetuka kune chikuru content Svetuka kuenda kudocs navigation
in English

Popover

Zvinyorwa uye mienzaniso yekuwedzera Bootstrap popovers, seaya anowanikwa muIOS, kune chero chinhu pane yako saiti.

Overview

Zvinhu zvekuziva kana uchishandisa popover plugin:

  • Popovers vanovimba neyechitatu bato raibhurari Popper yekumisikidza . Unofanira kusanganisira popper.min.js pamberi bootstrap.js kana kushandisa bootstrap.bundle.min.js/ bootstrap.bundle.jsiyo ine Popper kuitira kuti popovers kushanda!
  • Popovers inoda iyo tooltip plugin sekutsamira .
  • Mapopovers anosarudza-kupinda nekuda kwezvikonzero zvekuita, saka iwe unofanirwa kuzvitangisa iwe pachako .
  • Zero-kureba titleuye contentkukosha hazvizomboratidzi popover.
  • Nyora container: 'body'kudzivirira kupa matambudziko muzvikamu zvakaoma zvikuru (semapoka edu ekuisa, mapoka emabhatani, nezvimwe).
  • Kukurudzira popover pazvinhu zvakavanzika hazvishande.
  • Mapopovers e .disabledkana ma disabledelement anofanira kukonzereswa pane wrapper element.
  • Kana ikamutswa kubva kune zvibatiso zvinoputira mumitsetse yakawanda, mapopovers achange ari pakati pehupamhi hwezvimiso. Shandisa .text-nowrappane yako <a>kudzivirira maitiro aya.
  • Mapopover anofanirwa kuvanzwa zvinhu zvawo zvinowirirana zvisati zvabviswa muDOM.
  • Popovers inogona kukonzereswa nekuda kwechinhu chiri mukati memumvuri DOM.
Nekumisikidza, chikamu ichi chinoshandisa yakavakirwa-mukati sanitizer, iyo inobvisa chero zvinhu zveHTML zvisingabvumirwe zvakajeka. Ona chikamu che sanitizer mune yedu JavaScript zvinyorwa kuti uwane rumwe ruzivo.
Iyo animation mhedzisiro yechikamu ichi zvinoenderana prefers-reduced-motionnemubvunzo wenhau. Ona chikamu chakaderedzwa chezvinyorwa zvedu zvekusvikika .

Ramba uchiverenga kuti uone mashandiro anoita popover nemimwe mienzaniso.

Muenzaniso: Gonesa popovers kwese kwese

Imwe nzira yekutanga mapopovers pane peji ingave yekuvasarudza nehunhu hwavo data-bs-toggle:

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

Muenzaniso: Kushandisa containersarudzo

Paunenge uine mamwe masitayera pane chinhu chemubereki chinokanganisa popover, iwe unozoda kutsanangura tsika containerkuitira kuti popover's HTML ioneke mukati mechinhu ichocho.

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

Muenzaniso

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

Nzira ina

Sarudzo ina dziripo: kumusoro, kurudyi, pasi, uye kuruboshwe zvakaenderana. Mafambiro anotaridzwa kana uchishandisa Bootstrap muRTL.

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

Ramba paunodzvanya kunotevera

Shandisa focuschibatiso kuti udzinge mapopovers pakudzvanya kunotevera kwemushandisi kwechimwe chinhu pane chekuchinja.

Yakananga markup inodiwa pakubvisa-pa-inotevera-kubaya

Kuti uwane chaiyo-muchinjika-browser uye muchinjika-chikuva maitiro, iwe unofanirwa kushandisa iyo <a>tag, kwete iyo <button>tag, uye iwe zvakare unofanirwa kusanganisira tabindexhunhu.

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

Zvinhu zvakaremara

Zvinhu zvine disabledhunhu hazvidyidzane, zvichireva kuti vashandisi havagone kusimudza kana kudzvanya kuti vakonzerese popover (kana tooltip). Sekushanda, iwe unozoda kukonzeresa popover kubva pakuputira <div>kana <span>, yakanyatsogadzirwa keyboard-inotariswa uchishandisa tabindex="0".

Kune akaremara popover zvinokonzeresa, unogona zvakare kuda data-bs-trigger="hover focus"kuitira kuti popover ioneke semhinduro yekuona nekukurumidza kune vashandisi vako sezvo vangasatarisira kudzvanya chinhu chakaremara.

<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

Variables

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

Usage

Gonesa mapopovers kuburikidza neJavaScript:

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

Kugadzira mapopovers kushandira kiibhodhi uye vanobatsira tekinoroji vashandisi

Kuti ubvumire vashandisi vekhibhodi kuti vavhure mapopovers ako, iwe unofanirwa kungoawedzera kune HTML zvinhu zvinogara zvichitariswa nekhibhodi uye zvinopindirana (senge zvinongedzo kana mafomu ekudzora). Kunyangwe zvinopokana zveHTML zvinhu ( <span>senge s) zvichigona kuitwa kuti zvitarisike nekuwedzera tabindex="0"hunhu, izvi zvinowedzera zvinogona kutsamwisa uye zvinovhiringa tebhu inomira pazvinhu zvisiri-zvinopindirana zvevashandisi vekhibhodi, uye matekinoroji mazhinji anobatsira parizvino haazivise zviri mupopover mumamiriro ezvinhu aya. . Pamusoro pezvo, usavimbe chete hoversechinhu chinokonzeresa chepopovers yako, sezvo izvi zvichizoita kuti vasakwanise kukonzeresa vashandisi vekhibhodi.

Nepo iwe uchigona kuisa yakapfuma, yakarongeka HTML mumapopovers htmlnesarudzo, isu tinokurudzira zvakasimba kuti udzivise kuwedzera huwandu hwakawandisa hwemukati. Mashandiro anoita popovers parizvino ndeyekuti, kana angoratidzwa, zvirimo zvakasungirirwa kune chinokonzeresa chinhu aria-describedbynehunhu. Nekuda kweizvozvo, zvese zvemukati zvepopover zvichaziviswa kune vabatsiri tekinoroji vashandisi serukova rwumwe rurefu rusina kukanganiswa.

Pamusoro pezvo, kunyangwe zvichikwanisika kusanganisa anodyidzana zvidzoreso (senge fomu zvinhu kana zvinongedzo) mune yako popover (nekuwedzera zvinhu izvi kune allowListinotenderwa hunhu uye ma tag), ziva kuti parizvino popover haigadzirise keyboard yekutarisa kurongeka. Kana mushandisi wekhibhodi akavhura popover, kutarisa kunoramba kuri pachinhu chinokonzeresa, uye sezvo iyo popover kazhinji isinga tevere mutsara muchimiro chegwaro, hapana vimbiso yekuti kuenda kumberi / kudzvanya.TABichafambisa mushandisi wekhibhodi mupopover pachayo. Muchidimbu, kungowedzera anodyidzana zvidzoreso kune popover zvinogona kuita kuti zvigadziriso izvi zvisasvike / kusashandika kune vashandisi vekhibhodi nevashandisi vetekinoroji yekubatsira, kana padiki gadzira iyo isina musoro yekutarisa kurongeka. Muzviitiko izvi, funga kushandisa modal dialog pane.

Options

Sarudzo dzinogona kupfuudzwa kuburikidza nedata hunhu kana JavaScript. Nezve data hunhu, wedzera iyo sarudzo zita ku data-bs-, semu data-bs-animation="". Ita shuwa yekushandura iyo kesi mhando yezita resarudzo kubva kameraCase kuenda ku kebab-kesi kana uchipfuura sarudzo kuburikidza ne data hunhu. Semuenzaniso, pane kushandisa data-bs-customClass="beautifier", shandisa data-bs-custom-class="beautifier".

Ziva kuti nekuda kwezvikonzero zvekuchengetedza iyo sanitize,, sanitizeFnuye allowListsarudzo haigone kupihwa uchishandisa data hunhu.
Zita Type Default Tsanangudzo
animation boolean true Isa CSS fade shanduko kune popover
container tambo | chinhu | nhema false

Inoisa popover kune chimwe chinhu. Muenzaniso container: 'body':. Iyi sarudzo inonyanya kubatsira mukuti inobvumidza iwe kuti uise iyo popover mukuyerera kwegwaro padhuze nechinhu chinokonzeresa - izvo zvinodzivirira iyo popover kuti irege kuyangarara kubva kune inokonzeresa chinhu panguva yehwindo resize.

content tambo | chinhu | basa ''

Default content value kana data-bs-contenthunhu husipo.

Kana basa rakapihwa, rinodaidzwa nereferensi yaro thisyakaiswa kune chinhu icho popover inonamatira.

delay nhamba | object 0

Kunonoka kuratidza uye kuvanza iyo popover (ms) - haishande kune manual trigger type

Kana nhamba yapihwa, kunonoka kunoiswa kune ese ari maviri hide/show

Chimiro chechinhu ndeichi:delay: { "show": 500, "hide": 100 }

html boolean false Isa HTML mune popover. Kana zvisiri izvo, innerTextzvivakwa zvichashandiswa kuisa zvirimo muDOM. Shandisa zvinyorwa kana uchinetseka nezve XSS kurwiswa.
placement tambo | basa 'right'

Maitiro ekuisa iyo popover - auto | pamusoro | pasi | left | rudyi.
Kana autoyatsanangurwa, ichaita dynamically kurongedza popover.

Kana basa rikashandiswa kuona kuiswa, rinodaidzwa nepopover DOM node senharo yayo yekutanga uye chinokonzeresa DOM node sechipiri. Mamiriro thisacho akaiswa kune iyo popover muenzaniso.

selector tambo | nhema false Kana sarudzo yakapihwa, popover zvinhu zvinopihwa kune izvo zvakatarwa. Mukuita, izvi zvinoshandiswa kugonesa dynamic HTML zvemukati kuve nemapopovers akawedzerwa. Ona izvi uye muenzaniso unodzidzisa .
template tambo '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'

Base HTML yekushandisa paunenge uchigadzira popover.

Iyo popover's titleichabaiwa mu .popover-header.

Iyo popover's contentichabaiwa mu .popover-body.

.popover-arrowuchava museve wavapfuri.

Chinhu chekunze chekuputira chinofanira kunge chine .popoverkirasi.

title tambo | chinhu | basa ''

Default title value kana titlehunhu husipo.

Kana basa rakapihwa, rinodaidzwa nereferensi yaro thisyakaiswa kune chinhu icho popover inonamatira.

trigger tambo 'click' Iyo popover inokonzereswa sei - tinya | hovha | focus | manual. Unogona kupfuura akawanda anokonzeresa; vaparadzanise nenzvimbo. manualhaigone kusanganiswa nechero imwe trigger.
fallbackPlacements array ['top', 'right', 'bottom', 'left'] Tsanangura nzvimbo dzekudzokera kumashure nekupa runyoro rwekuiswa muhurongwa (mukurongeka kwekuda). Kuti uwane rumwe ruzivo tarisa kuPopper's behaviour docs
boundary tambo | element 'clippingParents' Kufashukira kunomanikidza muganho wepopover (inoshanda chete kune Popper's kudziviriraOverflow modifier). Nekusagadzikana 'clippingParents'ndeye uye inogona kugamuchira HTMLElement referensi (kuburikidza neJavaScript chete). Kuti uwane rumwe ruzivo tarisa kuPopper's detectOverflow docs .
customClass tambo | basa ''

Wedzera makirasi kune popover kana yaratidzwa. Ziva kuti makirasi aya achawedzerwa kune chero makirasi anotsanangurwa mutemplate. Kuwedzera makirasi akawanda, aparadzanise nenzvimbo: 'class-1 class-2'.

Iwe unogona zvakare kupasa basa rinofanira kudzosa tambo imwe ine mamwe mazita ekirasi.

sanitize boolean true Gonesa kana kudzima sanitization. Kana ikashandiswa 'template', 'content'uye 'title'sarudzo dzichacheneswa. Ona chikamu che sanitizer mune yedu JavaScript zvinyorwa .
allowList object Default value Chinhu chine hunhu uye ma tag anotenderwa
sanitizeFn null | basa null Pano iwe unogona kupa yako wega sanitize basa. Izvi zvinogona kubatsira kana ukada kushandisa raibhurari yakatsaurirwa kuita sanitization.
offset array | tambo | basa [0, 8]

Offset ye poover inoenderana nechinangwa chayo. Iwe unogona kupfuudza tambo mune data hunhu ine comma yakapatsanurwa kukosha senge:data-bs-offset="10,20"

Kana basa rinoshandiswa kuona kumisa, rinodanwa nechinhu chine popper placement, referensi, uye popper rects senharo yayo yekutanga. Iyo inokonzeresa element DOM node inopfuudzwa seyechipiri nharo. Basa racho rinofanira kudzosa rondedzero ine nhamba mbiri: .[skidding, distance]

Kuti uwane rumwe ruzivo tarisa kuPopper's offset docs .

popperConfig null | chinhu | basa null

Kuti uchinje Bootstrap's default Popper config, ona Popper's configuration .

Kana basa richishandiswa kugadzira iyo Popper kumisikidzwa, inodanwa nechinhu chine Bootstrap's default Popper kumisikidzwa. Inokubatsira kushandisa uye kubatanidza iyo yakasarudzika neyako gadziriso. Basa racho rinofanira kudzorera chinhu chekugadzirisa chePopper.

Data hunhu hwemunhu popovers

Sarudzo dzemapopovers ega dzinogona kutsanangurwa neimwe nzira kuburikidza nekushandisa data hunhu, sezvatsanangurwa pamusoro.

Kushandisa basa nepopperConfig

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

Nzira

Asynchronous nzira uye shanduko

Yese nzira dzeAPI dzine asynchronous uye dzinotanga shanduko . Vanodzokera kumunhu anenge afona pachangotanga shanduko asi isati yapera . Pamusoro pezvo, kufona kwenzira pachikamu chekuchinja kuchafuratirwa .

Ona zvinyorwa zvedu zveJavaScript kuti uwane rumwe ruzivo .

show

Inoratidza kubuda kwechimwe chinhu. Inodzokera kumunhu arikufona popover isati yanyatsoratidzwa (kureva kuti shown.bs.popoverchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yehupover. Mapopovers ane zita uye zvirimo zvese zviri zero-kureba hazvimbotaridzwa.

myPopover.show()

hide

Inovanza kubuda kwechinhu. Inodzokera kune ari kufona popover isati yanyatsovanzwa (kureva hidden.bs.popoverchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yehupover.

myPopover.hide()

toggle

Inoshandura kubuda kwechinhu. Inodzokera kumunhu arikufona popover isati yanyatsoratidzwa kana kuvanzwa (kureva kuti shown.bs.popoverkana hidden.bs.popoverchiitiko chisati chaitika). Izvi zvinoonekwa se "manual" inokonzeresa yehupover.

myPopover.toggle()

kurasa

Inovanza uye inoparadza popover yechinhu (Inobvisa data rakachengetwa pachinhu cheDOM). Mapopover anoshandisa kugovera (ayo anogadzirwa pachishandiswa sarudzoselector ) haagone kuparadzwa ega pane zvinokonzeresa zvinhu .

myPopover.dispose()

enable

Inopa element's popover kugona kuratidzwa. Popovers inogoneswa neiyo default.

myPopover.enable()

disable

Inobvisa kugona kwechinhu chinobuda pachena. Iyo popover inongo kwanisa kuratidzwa kana ikabatidzwa zvakare.

myPopover.disable()

toggleEnabled

Inosandura kugona kwechinhu chinobuda kuti chiratidze kana kuvanzwa.

myPopover.toggleEnabled()

update

Inovandudza nzvimbo yechinhu chinobuda.

myPopover.update()

getInstance

Static nzira iyo inokutendera iwe kuti uwane iyo popover muenzaniso yakabatana neiyo DOM chinhu

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

getOrCreateInstance

Static nzira iyo inokutendera iwe kuti uwane iyo popover muenzaniso yakabatana neiyo DOM chinhu, kana kugadzira imwe nyowani kana isina kutangwa.

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

Zviitiko

Chiitiko mhando Tsanangudzo
show.bs.popover Ichi chiitiko chinopisa nekukasira kana shownzira yemuenzaniso inodanwa.
display.bs.popover Ichi chiitiko chinodzingwa kana popover yaitwa kuti ionekwe kumushandisi (inomirira kuti CSS shanduko ipedze).
hide.bs.popover Ichi chiitiko chinodzingwa nekukasira kana iyo hidemuenzaniso nzira yadaidzwa.
zvakavanzika.bs.popover Ichi chiitiko chinodzingwa kana popover yapedza kuvanzwa kubva kumushandisi (inomirira kuti CSS shanduko ipedze).
inserted.bs.popover Ichi chiitiko chinodzingwa mushure show.bs.popovermechiitiko apo popover template yawedzerwa kuDOM.
var myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
  // do something...
})