Source

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.js 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.js txhawm rau kom popovers ua haujlwm!
  • Popovers xav tau lub tooltip plugin raws li kev vam khom.
  • Yog tias koj tab tom tsim peb JavaScript los ntawm qhov chaw, nws xav tauutil.js .
  • 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.

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-toggletus cwj pwm:

$(function () {
  $('[data-toggle="popover"]').popover()
})

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.

$(function () {
  $('.example-popover').popover({
    container: 'body'
  })
})

Piv txwv

<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-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.

<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="top" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
  Popover on top
</button>

<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="right" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
  Popover on right
</button>

<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Vivamus
sagittis lacus vel augue laoreet rutrum faucibus.">
  Popover on bottom
</button>

<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="left" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
  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-toggle="popover" data-trigger="focus" title="Dismissible popover" data-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
$('.popover-dismiss').popover({
  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>lossis <span>thiab override rau pointer-eventsntawm lub caij tsis taus.

Rau cov neeg xiam oob qhab popover tshwm sim, koj kuj tseem xav tau data-trigger="hover"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" data-toggle="popover" data-content="Disabled popover">
  <button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
</span>

Kev siv

Qhib popovers ntawm JavaScript:

$('#example').popover(options)

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-, xws li hauv data-animation="".

Lub npe Hom Default Kev piav qhia
animation boolean muaj tseeb Siv CSS ploj mus rau qhov popover
thawv hlua | element | cuav cuav

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.

cov ntsiab lus hlua | element | muaj nuj nqi ''

Default ntsiab lus tus nqi yog data-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.

ncua 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 cuav Ntxig HTML rau hauv popover. Yog tias tsis tseeb, jQuery txoj textkev yuav raug siv los ntxig cov ntsiab lus rau hauv DOM. Siv cov ntawv nyeem yog tias koj txhawj xeeb txog XSS tawm tsam.
tso chaw hlua | muaj nuj nqi 'txoj cai'

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.

xaiv hlua | cuav cuav 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 .
tus qauv txoj hlua '<div class="popover" role="tooltip"><div class="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.

.arrowyuav dhau los ua tus popover tus xub.

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

lub npe 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.

ua rau txoj hlua 'nias' 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.
offset tus lej | txoj hlua 0 Offset ntawm popover txheeb ze rau nws lub hom phiaj. Yog xav paub ntxiv mus saib Popper.js's offset docs .
fallbackPlacement hlua | array 'rov qab' Tso cai kom qhia meej tias txoj hauj lwm twg Popper yuav siv rau qhov poob. Yog xav paub ntxiv mus saib Popper.js tus cwj pwm docs
ciam teb hlua | keeb 'scrollParent' Overflow constraint ciam teb ntawm lub popover. Txais cov txiaj ntsig ntawm 'viewport', 'window', 'scrollParent', lossis HTMLElement siv (JavaScript nkaus xwb). Yog xav paub ntxiv mus saib Popper.js's PreventOverflow docs .

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.

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.

$().popover(options)

Initializes popovers rau ib qho khoom sau.

.popover('show')

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 ob lub npe thiab cov ntsiab lus yog xoom-ntev yeej tsis tshwm sim.

$('#element').popover('show')

.popover('hide')

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.

$('#element').popover('hide')

.popover('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.

$('#element').popover('toggle')

.popover('dispose')

Nias thiab rhuav tshem lub ntsiab lus popover. 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.

$('#element').popover('dispose')

.popover('enable')

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

$('#element').popover('enable')

.popover('disable')

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

$('#element').popover('disable')

.popover('toggleEnabled')

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

$('#element').popover('toggleEnabled')

.popover('update')

Hloov tshiab txoj hauj lwm ntawm lub ntsiab lub popover.

$('#element').popover('update')

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.
$('#myPopover').on('hidden.bs.popover', function () {
  // do something…
})