Hla mus rau cov ntsiab lus tseem ceeb Hla mus rau docs navigation
in English

Popovers

Cov ntaub ntawv thiab cov piv txwv rau ntxiv Bootstrap popovers, zoo li cov uas pom hauv iOS no, rau ib qho ntawm koj qhov chaw.

Txheej txheem cej luam

Tej yam uas yuav tsum paub thaum siv lub popover plugin:

  • Popovers cia siab rau 3rd tog tsev qiv ntawv Popper rau qhov chaw. Koj yuav tsum suav nrog popper.min.js ua ntej bootstrap.js lossis siv bootstrap.bundle.min.js/ bootstrap.bundle.jsuas muaj Popper txhawm rau kom popovers ua haujlwm!
  • Popovers xav tau lub tooltip plugin raws li kev vam khom.
  • Popovers yog opt-in rau kev ua tau zoo vim li cas, yog li koj yuav tsum pib lawv tus kheej .
  • Zero-ntev titlethiab contentqhov tseem ceeb yuav tsis pom qhov popover.
  • Qhia container: 'body'kom tsis txhob muaj teeb meem nyob rau hauv cov khoom siv ntau dua (xws li peb cov tswv yim pab pawg, pawg khawm, thiab lwm yam).
  • Triggering popovers ntawm cov ntsiab lus zais yuav tsis ua haujlwm.
  • Popovers rau .disabledlos yog disabledcov ntsiab lus yuav tsum tau ua rau ntawm cov khoom siv wrapper.
  • Thaum tshwm sim los ntawm cov thauj tog rau nkoj uas qhwv hla ntau kab, popovers yuav nyob nruab nrab ntawm cov thauj tog rau nkoj 'tag nrho dav. Siv .text-nowrapkoj <a>tus kheej kom tsis txhob muaj tus cwj pwm no.
  • Popovers yuav tsum tau muab zais ua ntej lawv cov ntsiab lus sib raug tau raug tshem tawm ntawm DOM.
  • Popovers tuaj yeem tshwm sim ua tsaug rau cov khoom hauv ib qho duab ntxoov ntxoo DOM.
Los ntawm lub neej ntawd, cov khoom siv no siv cov khoom siv tshuaj tua kab mob, uas tshem tawm cov ntsiab lus HTML uas tsis tau tso cai. Saib cov tshuaj ntxuav tes hauv peb cov ntaub ntawv JavaScript kom paub meej ntxiv.
Cov nyhuv animation ntawm cov khoom siv no yog nyob ntawm cov prefers-reduced-motionlus nug xov xwm. Saib qhov txo qis ntawm peb cov ntaub ntawv nkag mus tau .

Khaws nyeem kom pom tias popovers ua haujlwm li cas nrog qee qhov piv txwv.

Piv txwv: Pab kom popovers txhua qhov chaw

Ib txoj hauv kev los pib tag nrho cov popovers ntawm nplooj ntawv yuav yog xaiv lawv los ntawm lawv data-bs-toggletus cwj pwm:

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

Piv txwv: Siv qhov containerkev xaiv

Thaum koj muaj qee tus qauv ntawm niam txiv lub caij uas cuam tshuam nrog lub popover, koj yuav xav qhia qhov kev cai containerkom cov popover's HTML tshwm nyob rau hauv cov khoom ntawd.

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

Piv txwv

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

Plaub txoj kev

Plaub txoj kev xaiv muaj: sab saum toj, sab xis, hauv qab, thiab sab laug dlhos. Cov lus qhia tau mirrored thaum siv Bootstrap hauv 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>

Tshem tawm ntawm qhov nyem tom ntej

Siv qhov focusua kom tshem tawm cov popovers ntawm tus neeg siv tom ntej nyem ntawm ib lub caij sib txawv dua li qhov hloov pauv.

Cov cim tshwj xeeb xav tau rau kev tshem tawm-ntawm-tom ntej-nias

Txhawm rau kom tus neeg siv khoom sib txawv thiab tus cwj pwm hla lub platform, koj yuav tsum siv lub <a>cim npe, tsis yog lub <button>cim, thiab koj kuj yuav tsum muaj tus tabindexcwj pwm.

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

Cov neeg xiam oob qhab

Cov ntsiab lus nrog tus disabledcwj pwm tsis sib cuam tshuam, txhais tau tias cov neeg siv tsis tuaj yeem txav los yog nyem rau lawv kom ua rau popover (lossis cov lus qhia). Raws li kev daws teeb meem, koj yuav xav ua kom lub popover los ntawm lub wrapper <div>los yog <span>, qhov zoo tshaj plaws ua keyboard-focusable siv tabindex="0".

Rau cov neeg xiam oob qhab popover tshwm sim, koj kuj tseem xav tau data-bs-trigger="hover focus"kom cov popover tshwm sim tam sim pom kev tawm tswv yim rau koj cov neeg siv vim lawv yuav tsis xav tias yuav nyem rau ntawm qhov chaw xiam oob qhab.

<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

Hloov pauv

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

Kev siv

Qhib popovers ntawm JavaScript:

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

Ua popovers ua haujlwm rau cov keyboard thiab cov neeg siv thev naus laus zis

Txhawm rau tso cai rau cov neeg siv cov keyboard kom qhib koj cov popovers, koj tsuas yog yuav tsum ntxiv lawv rau HTML cov ntsiab lus uas ib txwm muaj cov keyboard-focusable thiab sib tham sib (xws li kev sib txuas lossis daim ntawv tswj). Txawm hais tias cov ntsiab lus HTML arbitrary (xws li <span>s) tuaj yeem ua kom pom tseeb los ntawm kev ntxiv tus tabindex="0"cwj pwm, qhov no yuav ntxiv qhov cuam tshuam thiab tsis meej pem tab nres ntawm cov ntsiab lus tsis sib tham rau cov neeg siv cov keyboard, thiab cov cuab yeej pabcuam feem ntau tam sim no tsis tshaj tawm cov ntsiab lus popover hauv qhov xwm txheej no. . Tsis tas li ntawd, tsis txhob cia siab ib leeg los hoverua qhov ua rau koj cov popovers, vim qhov no yuav ua rau lawv tsis tuaj yeem ua rau cov neeg siv keyboard.

Thaum koj tuaj yeem ntxig cov nplua nuj, tsim HTML hauv popovers nrog kev htmlxaiv, peb xav kom koj tsis txhob ntxiv cov ntsiab lus ntau dhau. Txoj kev popovers tam sim no ua haujlwm yog tias, ib zaug tso tawm, lawv cov ntsiab lus raug khi rau lub ntsiab lus nrog tus aria-describedbycwj pwm. Raws li qhov tshwm sim, tag nrho ntawm cov ntsiab lus popover yuav raug tshaj tawm rau cov neeg siv thev naus laus zis ua ib qho ntev, tsis muaj kev cuam tshuam.

Tsis tas li ntawd, thaum nws tseem tuaj yeem suav nrog kev sib tham sib tswj (xws li cov ntsiab lus lossis cov ntawv txuas) hauv koj lub popover (los ntawm kev ntxiv cov ntsiab lus no rau allowListntawm cov khoom tso cai thiab cov cim npe), nco ntsoov tias tam sim no lub popover tsis tswj cov keyboard tsom xam xaj. Thaum tus neeg siv cov keyboard qhib lub popover, tsom mus rau qhov tshwm sim, thiab raws li qhov popover feem ntau tsis ua raws li qhov tshwm sim tam sim ntawd hauv cov ntaub ntawv tus qauv, tsis muaj kev lees paub tias mus tom ntej / nias.TAByuav txav tus neeg siv keyboard rau hauv popover nws tus kheej. Nyob rau hauv luv luv, tsuas yog ntxiv kev sib tham sib tswj rau ib tug popover yog yuav ua rau cov kev tswj tsis mus cuag / siv tsis tau rau cov neeg siv keyboard thiab cov neeg siv cov cuab yeej pab, los yog tsawg kawg yog ua rau ib tug illogical zuag qhia tag nrho kev txiav txim. Nyob rau hauv cov ntaub ntawv no, xav txog siv ib tug modal dialog xwb.

Kev xaiv

Cov kev xaiv tuaj yeem dhau los ntawm cov ntaub ntawv tus cwj pwm lossis JavaScript. Rau cov ntaub ntawv tus cwj pwm, ntxiv rau qhov kev xaiv npe rau data-bs-, xws li hauv data-bs-animation="". Nco ntsoov hloov cov ntaub ntawv ntawm lub npe xaiv los ntawm camelCase mus rau kebab-cov ntaub ntawv thaum dhau cov kev xaiv ntawm cov ntaub ntawv cwj pwm. Piv txwv li, es tsis txhob siv data-bs-customClass="beautifier", siv data-bs-custom-class="beautifier".

Nco ntsoov tias yog vim li cas kev ruaj ntseg sanitize, sanitizeFn, thiab allowListcov kev xaiv tsis tuaj yeem muab siv cov ntaub ntawv tus cwj pwm.
Lub npe Hom Default Kev piav qhia
animation boolean true Siv CSS ploj mus rau qhov popover
container hlua | element | cuav false

Appends lub popover rau ib lub caij tshwj xeeb. container: 'body'Piv txwv :. Qhov kev xaiv no yog qhov tshwj xeeb tshaj yog nyob rau hauv uas nws tso cai rau koj tso lub popover nyob rau hauv qhov ntws ntawm cov ntaub ntawv nyob ze ntawm lub triggering lub caij - uas yuav tiv thaiv lub popover los ntawm floating deb ntawm lub triggering lub sij hawm thaum lub qhov rais resize.

content hlua | element | muaj nuj nqi ''

Default ntsiab lus tus nqi yog data-bs-contentattribute tsis nyob.

Yog tias muaj nuj nqi tau muab, nws yuav raug hu nrog nws cov thisntaub ntawv teev rau lub caij uas lub popover txuas nrog.

delay tus lej | khoom 0

ncua kev qhia thiab zais qhov popover (ms) - tsis siv rau phau ntawv txhais hom

Yog tias muaj tus lej nkag, ncua sijhawm yog siv rau ob qho tib si zais / qhia

Object structure yog:delay: { "show": 500, "hide": 100 }

html boolean false Ntxig HTML rau hauv popover. Yog tias tsis tseeb, innerTextcov cuab yeej yuav raug siv los ntxig cov ntsiab lus rau hauv DOM. Siv cov ntawv nyeem yog tias koj txhawj xeeb txog XSS tawm tsam.
placement hlua | muaj nuj nqi 'right'

Yuav ua li cas tso lub popover - pib | saum | hauv qab | sab laug | txoj cai.
Thaum autotau teev tseg, nws yuav dynamically reorient lub popover.

Thaum muaj nuj nqi yog siv los txiav txim qhov kev tso kawm, nws raug hu nrog popover DOM node raws li nws thawj qhov kev sib cav thiab lub triggering ntsiab DOM node raws li nws thib ob. Cov thisntsiab lus tau teeb tsa rau qhov piv txwv popover.

selector hlua | cuav false Yog tias muaj ib tus neeg xaiv tau muab, cov khoom popover yuav raug xa mus rau cov phiaj xwm tshwj xeeb. Hauv kev xyaum, qhov no yog siv los ua kom cov ntsiab lus HTML dynamic kom muaj popovers ntxiv. Saib qhov no thiab ib qho piv txwv qhia .
template txoj hlua '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'

Base HTML siv thaum tsim cov popover.

Popover's titleyuav raug txhaj rau hauv lub .popover-header.

Popover's contentyuav raug txhaj rau hauv lub .popover-body.

.popover-arrowyuav dhau los ua tus popover tus xub.

Cov txheej txheem wrapper sab nraud yuav tsum muaj .popoverchav kawm.

title hlua | element | muaj nuj nqi ''

Default title value yog titleattribute tsis nyob.

Yog tias muaj nuj nqi tau muab, nws yuav raug hu nrog nws cov thisntaub ntawv teev rau lub caij uas lub popover txuas nrog.

trigger txoj hlua 'click' Yuav ua li cas popover yog triggered - nyem | hover | tsom | phau ntawv. Koj tuaj yeem hla ntau qhov ua rau; cais lawv nrog ib qho chaw. manualtsis tuaj yeem ua ke nrog lwm qhov ua rau.
fallbackPlacements array ['top', 'right', 'bottom', 'left'] Txheeb xyuas qhov chaw rov qab los ntawm kev muab cov npe ntawm qhov chaw nyob hauv array (hauv kev txiav txim siab). Yog xav paub ntxiv mus saib Popper tus cwj pwm docs
boundary hlua | keeb 'clippingParents' Overflow txwv ciam teb ntawm lub popover (tsuas yog siv rau Popper's PreventOverflow modifier). Los ntawm lub neej ntawd nws yog 'clippingParents'thiab tuaj yeem lees txais HTMLElement siv (ntawm JavaScript nkaus xwb). Yog xav paub ntxiv mus saib Popper's detectOverflow docs .
customClass hlua | muaj nuj nqi ''

Ntxiv cov chav kawm rau lub popover thaum nws pom. Nco ntsoov tias cov chav kawm no yuav muab ntxiv ntxiv rau cov chav kawm uas tau teev tseg hauv cov qauv. Txhawm rau ntxiv ntau chav kawm, cais lawv nrog qhov chaw: 'class-1 class-2'.

Koj tuaj yeem dhau ib txoj haujlwm uas yuav tsum rov qab ib txoj hlua uas muaj cov npe hauv chav kawm ntxiv.

sanitize boolean true Qhib lossis kaw qhov kev huv huv. Yog tias qhib 'template', 'content'thiab 'title'cov kev xaiv yuav raug ntxuav. Saib cov tshuaj tua kab mob hauv peb cov ntaub ntawv JavaScript .
allowList khoom Default tus nqi Yam khoom uas muaj cov cwj pwm tso cai thiab cov cim npe
sanitizeFn null | muaj nuj nqi null Ntawm no koj tuaj yeem muab koj tus kheej ua haujlwm huv. Qhov no tuaj yeem pab tau yog tias koj xav siv lub tsev qiv ntawv tshwj xeeb los ua kom huv.
offset array | hlua | muaj nuj nqi [0, 8]

Offset ntawm popover txheeb ze rau nws lub hom phiaj. Koj tuaj yeem hla ib txoj hlua hauv cov ntaub ntawv tus cwj pwm nrog comma cais qhov tseem ceeb xws li:data-bs-offset="10,20"

Thaum muaj nuj nqi yog siv los txiav txim qhov offset, nws raug hu nrog ib yam khoom uas muaj cov popper qhov chaw, siv, thiab popper rects raws li nws thawj qhov kev sib cav. Lub triggering element DOM node tau dhau los ua qhov kev sib cav thib ob. Cov haujlwm yuav tsum xa rov qab ib qho array nrog ob tus lej: .[skidding, distance]

Yog xav paub ntxiv mus saib Popper's offset docs .

popperConfig null | khoom | muaj nuj nqi null

Txhawm rau hloov Bootstrap's default Popper config, saib Popper's configuration .

Thaum muaj nuj nqi siv los tsim Popper teeb tsa, nws tau hu nrog ib qho khoom uas muaj Bootstrap's default Popper configuration. Nws pab koj siv thiab ua ke lub neej ntawd nrog koj tus kheej configuration. Cov haujlwm yuav tsum xa rov qab cov khoom teeb tsa rau Popper.

Cov ntaub ntawv tus cwj pwm rau tus kheej popovers

Kev xaiv rau ib tus neeg popovers tuaj yeem hloov tau los ntawm kev siv cov ntaub ntawv tus cwj pwm, raws li tau piav qhia saum toj no.

Siv ua haujlwm nrogpopperConfig

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

Cov txheej txheem

Asynchronous txoj kev thiab kev hloov

Txhua txoj kev API yog asynchronous thiab pib hloov pauv . Lawv rov qab mus rau tus neeg hu xov tooj sai li sai tau thaum qhov kev hloov pauv pib tab sis ua ntej nws xaus . Tsis tas li ntawd, ib txoj kev hu rau ib qho kev hloov pauv yuav raug tsis quav ntsej .

Saib peb cov ntaub ntawv JavaScript kom paub ntau ntxiv .

ua yeeb yam

Qhia ib lub ntsiab lus popover. Rov qab mus rau tus neeg hu ua ntej qhov popover tau tshwm sim tiag tiag (piv txwv li ua ntej qhov shown.bs.popoverxwm txheej tshwm sim). Qhov no suav hais tias yog "kev tuav tswj" ua rau lub popover. Popovers uas nws lub npe thiab cov ntsiab lus yog xoom-ntev yeej tsis tshwm sim.

myPopover.show()

zais

Hide ib lub ntsiab lus popover. Rov qab mus rau tus neeg hu ua ntej qhov popover tau muab zais tiag tiag (piv txwv li ua ntej qhov hidden.bs.popoverxwm txheej tshwm sim). Qhov no suav hais tias yog "kev tuav tswj" ua rau lub popover.

myPopover.hide()

toggle

Toggles ib lub ntsiab lus popover. Rov qab mus rau tus neeg hu ua ntej lub popover tau tshwm sim los yog zais (piv txwv li ua ntej qhov shown.bs.popoverkev hidden.bs.popovertshwm sim tshwm sim). Qhov no suav hais tias yog "kev tuav tswj" ua rau lub popover.

myPopover.toggle()

pov tseg

Nkaum thiab rhuav tshem lub ntsiab lus popover (Tshem cov ntaub ntawv khaws cia ntawm DOM lub caij). Popovers uas siv delegation (uas yog tsim los ntawm selectorkev xaiv ) tsis tuaj yeem raug rhuav tshem ib tus zuj zus ntawm cov xeeb leej xeeb ntxwv.

myPopover.dispose()

pab

Muab ib qho chaw popover lub peev xwm los qhia. Popovers tau qhib los ntawm lub neej ntawd.

myPopover.enable()

lov tes taw

Tshem tawm lub peev xwm rau lub ntsiab lus popover kom pom. Lub popover tsuas tuaj yeem pom yog tias nws rov qhib dua.

myPopover.disable()

toggleEnabled

Toggles lub peev xwm rau lub ntsiab lub popover kom pom los yog zais.

myPopover.toggleEnabled()

hloov tshiab

Hloov tshiab txoj hauj lwm ntawm lub ntsiab lub popover.

myPopover.update()

getInstance

Txoj kev zoo li qub uas tso cai rau koj kom tau txais qhov piv txwv popover txuam nrog DOM keeb

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

getOrCreateInstance

Txoj kev zoo li qub uas tso cai rau koj kom tau txais qhov piv txwv popover txuam nrog DOM lub caij, lossis tsim ib qho tshiab yog tias nws tsis tau pib

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

Cov xwm txheej

Hom xwm txheej Kev piav qhia
show.bs.popover Qhov xwm txheej no tua hluav taws tam sim ntawd thaum showhu ua piv txwv.
pom.bs.popover Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub popover tau pom rau tus neeg siv (yuav tos rau CSS kev hloov pauv kom tiav).
hide.bs.popover Qhov xwm txheej no raug rho tawm haujlwm tam sim ntawd thaum hidehu ua piv txwv txoj kev.
zais.bs.popover Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub popover tiav lawm muab zais los ntawm tus neeg siv (yuav tos rau CSS kev hloov pauv kom tiav).
inserted.bs.popover Qhov kev tshwm sim no raug rho tawm haujlwm tom qab qhov show.bs.popovertshwm sim thaum lub popover template tau ntxiv rau DOM.
var myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
  // do something...
})