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.js
uas muaj Popper 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 tau
util.js
. - Popovers yog opt-in rau kev ua tau zoo vim li cas, yog li koj yuav tsum pib lawv tus kheej .
- Zero-ntev
title
thiabcontent
qhov 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
.disabled
los yogdisabled
cov 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-nowrap
koj<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.
prefers-reduced-motion
lus 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-toggle
tus cwj pwm:
$(function () {
$('[data-toggle="popover"]').popover()
})
Piv txwv: Siv qhov container
kev 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 container
kom 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="Top popover">
Popover on top
</button>
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="right" data-content="Right popover">
Popover on right
</button>
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Bottom popover">
Popover on bottom
</button>
<button type="button" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="left" data-content="Left popover">
Popover on left
</button>
Tshem tawm ntawm qhov nyem tom ntej
Siv qhov focus
ua 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 tabindex
cwj 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 disabled
cwj 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-events
ntawm 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)
GPU acceleration
Popovers qee zaum pom qhov muag plooj ntawm Windows 10 li vim GPU acceleration thiab hloov kho qhov system DPI. Qhov kev daws teeb meem rau qhov no hauv v4 yog txhawm rau kaw GPU acceleration raws li xav tau ntawm koj cov popovers.
Tswv yim kho:
Popper.Defaults.modifiers.computeStyle.gpuAcceleration = !(window.devicePixelRatio < 1.5 && /Win/.test(navigator.platform))
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 hover
ua 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 html
xaiv, 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-describedby
cwj 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 whiteList
lossis tso cai rau cov cwj pwm 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-
, xws li hauv data-animation=""
.
sanitize
,
sanitizeFn
thiab
whiteList
cov kev xaiv tsis tuaj yeem muab siv cov ntaub ntawv cwj pwm.
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. |
cov ntsiab lus | hlua | element | muaj nuj nqi | '' | Default ntsiab lus tus nqi yog Yog tias muaj nuj nqi tau muab, nws yuav raug hu nrog nws cov |
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: |
html | boolean | cuav | Ntxig HTML rau hauv popover. Yog tias tsis tseeb, jQuery txoj text kev 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 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 |
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 Popover's
Cov txheej txheem wrapper sab nraud yuav tsum muaj |
lub npe | hlua | element | muaj nuj nqi | '' | Default title value yog Yog tias muaj nuj nqi tau muab, nws yuav raug hu nrog nws cov |
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. manual tsis 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'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 tus cwj pwm 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: Koj tuaj yeem dhau ib txoj haujlwm uas yuav tsum rov qab ib txoj hlua uas muaj cov npe hauv chav kawm ntxiv. |
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's PreventOverflow docs . |
ua kom huv | boolean | muaj tseeb | 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 . |
daim ntawv dawb | khoom | Default tus nqi | Yam khoom uas muaj cov cwj pwm tso cai thiab cov cim npe |
huv Fn | 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. |
popperConfig | null | khoom | null | Txhawm rau hloov Bootstrap's default Popper config, saib Popper's configuration |
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 .
$().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.popover
xwm 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.
$('#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.popover
xwm 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.popover
kev hidden.bs.popover
tshwm 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 selector
kev 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 show hu 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 hide hu 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.popover tshwm sim thaum lub popover template tau ntxiv rau DOM. |
$('#myPopover').on('hidden.bs.popover', function () {
// do something...
})