Amashanyarazi
Inyandiko n'ingero zo kongera Bootstrap popovers, nkibisangwa muri iOS, kubintu byose kurubuga rwawe.
Incamake
Ibintu ugomba kumenya mugihe ukoresheje plugin ya popover:
- Popovers yishingikiriza kumasomero yandi masomero Popper kugirango ihagarare. Ugomba gushyiramo popper.min.js mbere
bootstrap.js
, cyangwa ukoreshe imwebootstrap.bundle.min.js
irimo Popper. - Popovers isaba plugin ya popover nkubwishingizi .
- Popovers ihitamo kubwimpamvu zikorwa, ugomba rero kubitangiza wenyine .
- Uburebure bwa zeru
title
n'indangagacirocontent
ntibizigera byerekana popover. - Kugaragaza
container: 'body'
kugirango wirinde gutanga ibibazo mubice byinshi bigoye (nkitsinda ryacu ryinjiza, amatsinda ya buto, nibindi). - Gukurura popovers kubintu byihishe ntabwo bizakora.
- Popovers ya
.disabled
cyangwadisabled
ibintu bigomba gukururwa kubintu bipfunyika. - Iyo bivuye ku byuma bifunga imirongo myinshi, popovers izaba hagati yubugari bwa rusange. Koresha
.text-nowrap
kuri<a>
s kugirango wirinde iyi myitwarire. - Popovers igomba guhishwa mbere yuko ibintu bihuye bivanwa muri DOM.
- Popovers irashobora gukururwa bitewe nikintu kiri imbere mu gicucu DOM.
prefers-reduced-motion
nibibazo byitangazamakuru. Reba igice
cyagabanijwe cyicyiciro cyibisobanuro byacu .
Komeza usome kugirango urebe uko popovers ikora hamwe ningero zimwe.
Ingero
Gushoboza popovers
Nkuko byavuzwe haruguru, ugomba gutangiza popovers mbere yuko zikoreshwa. Uburyo bumwe bwo gutangiza popovers zose kurupapuro rwaba ari uguhitamo data-bs-toggle
kubiranga, nka gutya:
const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]')
const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl))
Kubaho
Dukoresha JavaScript isa nigice cyo hejuru kugirango dutange popover ikurikira. Umutwe washyizweho unyuze data-bs-title
hamwe nibirimo umubiri ushyirwaho data-bs-content
.
title
muri
data-bs-title
HTML yawe. Iyo
title
ikoreshejwe, Popper izayisimbuza mu buryo bwikora hamwe
data-bs-title
nigihe ikintu cyatanzwe.
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" data-bs-title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
Ibyerekezo bine
Amahitamo ane arahari: hejuru, iburyo, hepfo, n'ibumoso. Icyerekezo kirimo indorerwamo mugihe ukoresheje Bootstrap muri RTL. Shiraho data-bs-placement
guhindura icyerekezo.
<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>
Customcontainer
Mugihe ufite uburyo bumwe kubintu byababyeyi bibangamira popover, uzashaka kwerekana imigenzo container
kugirango HTML ya popover igaragara muri kiriya kintu aho. Ibi birasanzwe mumeza yitabira, amatsinda yinjiza, nibindi bisa.
const popover = new bootstrap.Popover('.example-popover', {
container: 'body'
})
Ikindi kibazo aho uzashaka gushiraho imigenzo container
itomoye ni popovers imbere muburyo bwikiganiro , kugirango umenye neza ko popover ubwayo yongewe kumurongo. Ibi nibyingenzi byingenzi kuri popovers zirimo ibintu byungurana ibitekerezo - modal ibiganiro bizagusha umutego, kuberako keretse popover ari ikintu cyumwana cyuburyo, abakoresha ntibazashobora kwibanda cyangwa gukora ibyo bintu byimikorere.
const popover = new bootstrap.Popover('.example-popover', {
container: '.modal-body'
})
Kumenyekanisha ibicuruzwa
Wongeyeho muri v5.2.0Urashobora guhitamo isura ya popovers ukoresheje CSS ihinduka . Twashyizeho urwego rwihariye hamwe data-bs-custom-class="custom-popover"
no kugereranya imiterere yacu kandi tuyikoresha kugirango twirengagize bimwe mubihinduka bya CSS byaho.
.custom-popover {
--bs-popover-max-width: 200px;
--bs-popover-border-color: var(--bs-primary);
--bs-popover-header-bg: var(--bs-primary);
--bs-popover-header-color: var(--bs-white);
--bs-popover-body-padding-x: 1rem;
--bs-popover-body-padding-y: .5rem;
}
<button type="button" class="btn btn-secondary"
data-bs-toggle="popover" data-bs-placement="right"
data-bs-custom-class="custom-popover"
data-bs-title="Custom popover"
data-bs-content="This popover is themed via CSS variables.">
Custom popover
</button>
Kwirukana gukanda
Koresha focus
imbarutso kugirango wirukane popovers kumukoresha ukurikiraho ibintu bitandukanye kuruta guhinduranya.
Ikimenyetso cyihariye gisabwa kugirango wirukanwe-gukurikira-gukanda
Kuburyo bukwiye bwambukiranya-mbuga hamwe nimyitwarire ya platform, ugomba gukoresha <a>
tagi, ntabwo ari <button>
tagi, kandi ugomba no gushyiramo tabindex
ikiranga.
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
const popover = new bootstrap.Popover('.popover-dismiss', {
trigger: 'focus'
})
Ibintu byahagaritswe
Ibintu bifite disabled
ikiranga ntabwo bikorana, bivuze ko abakoresha badashobora kugendagenda cyangwa kubikanda kugirango batere popover (cyangwa ibikoresho). Nkumurimo wakazi, uzakenera gukurura popover uhereye kumuzingo <div>
cyangwa <span>
, nibyiza byakozwe na clavier-yibanze ukoresheje tabindex="0"
.
Kubimuga byahagaritswe byimikorere, urashobora kandi guhitamo data-bs-trigger="hover focus"
kugirango popover igaragara nkibisubizo byihuse kubakoresha nkuko badashobora gutegereza gukanda kubintu bimugaye.
<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>
CSS
Ibihinduka
Wongeyeho muri v5.2.0Nkigice cya Bootstrap igenda ihinduka CSS ihinduka, popovers ubu ikoresha CSS ihindagurika kumurongo .popover
kugirango wongere igihe-cyo kwihindura. Indangagaciro za CSS zihinduka zashyizweho binyuze kuri Sass, so Sass yihariye iracyashyigikiwe, nayo.
--#{$prefix}popover-zindex: #{$zindex-popover};
--#{$prefix}popover-max-width: #{$popover-max-width};
@include rfs($popover-font-size, --#{$prefix}popover-font-size);
--#{$prefix}popover-bg: #{$popover-bg};
--#{$prefix}popover-border-width: #{$popover-border-width};
--#{$prefix}popover-border-color: #{$popover-border-color};
--#{$prefix}popover-border-radius: #{$popover-border-radius};
--#{$prefix}popover-inner-border-radius: #{$popover-inner-border-radius};
--#{$prefix}popover-box-shadow: #{$popover-box-shadow};
--#{$prefix}popover-header-padding-x: #{$popover-header-padding-x};
--#{$prefix}popover-header-padding-y: #{$popover-header-padding-y};
@include rfs($popover-header-font-size, --#{$prefix}popover-header-font-size);
--#{$prefix}popover-header-color: #{$popover-header-color};
--#{$prefix}popover-header-bg: #{$popover-header-bg};
--#{$prefix}popover-body-padding-x: #{$popover-body-padding-x};
--#{$prefix}popover-body-padding-y: #{$popover-body-padding-y};
--#{$prefix}popover-body-color: #{$popover-body-color};
--#{$prefix}popover-arrow-width: #{$popover-arrow-width};
--#{$prefix}popover-arrow-height: #{$popover-arrow-height};
--#{$prefix}popover-arrow-border: var(--#{$prefix}popover-border-color);
Ibihinduka bya Sass
$popover-font-size: $font-size-sm;
$popover-bg: $white;
$popover-max-width: 276px;
$popover-border-width: $border-width;
$popover-border-color: var(--#{$prefix}border-color-translucent);
$popover-border-radius: $border-radius-lg;
$popover-inner-border-radius: subtract($popover-border-radius, $popover-border-width);
$popover-box-shadow: $box-shadow;
$popover-header-font-size: $font-size-base;
$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;
Ikoreshwa
Gushoboza popovers ukoresheje JavaScript:
const exampleEl = document.getElementById('example')
const popover = new bootstrap.Popover(exampleEl, options)
Gukora popovers ikora kuri clavier hamwe nabafasha gukoresha ikoranabuhanga
Kwemerera abakoresha clavier gukora enterineti yawe, ugomba kubongerera gusa kubintu bya HTML bisanzwe bisanzwe byibanze-byibanda kandi bigakorana (nkumuhuza cyangwa kugenzura imiterere). Nubwo ibice bya HTML uko bishakiye (nka <span>
s) bishobora gukorwa byibandwaho mukongeramo tabindex="0"
ikiranga, ibi bizongeramo ibishoboka birakaze kandi bitera urujijo guhagarika ibintu bidahuza abakoresha clavier, kandi tekinoroji ifasha muri iki gihe ntabwo itangaza ibiri muri popover muriki kibazo . Byongeye kandi, ntukishingikirize gusa hover
nkimbarutso ya popovers yawe, kuko ibi bizatuma badashobora gukurura abakoresha clavier.
Mugihe ushobora gushyiramo HTML ikungahaye, yubatswe muri popovers hamwe namahitamo html
, turagusaba cyane ko wirinda kongeramo ibintu birenze urugero. Uburyo popovers ikora kurubu nuko, iyo imaze kugaragara, ibiyirimo bihujwe na trigger element hamwe na aria-describedby
kiranga. Nkigisubizo, ibyuzuye muri popover bizatangazwa kugirango bifashe abakoresha ikoranabuhanga nkumugezi muremure, udahagarara.
Ikigeretse kuri ibyo, mugihe bishoboka ko ushiramo no kugenzura ibikorwa (nkibintu bigize imiterere cyangwa amahuza) muri popover yawe (wongeyeho ibi bintu kubintu allowList
byemewe byemewe na tagi), menya ko kuri ubu popover idacunga urutonde rwibanda kuri clavier. Iyo umukoresha wa clavier afunguye popover, intumbero iguma kubintu bitera, kandi nkuko popover idahita ikurikira imbarutso mumiterere yinyandiko, nta garanti yerekana ko gutera imbere / gukandaTABKwimura umukoresha wa clavier muri popover ubwayo. Muri make, gusa wongeyeho igenzura ryimikorere kuri popover birashoboka ko ibyo bigenzurwa bitagerwaho / bidakoreshwa kubakoresha clavier hamwe nabakoresha tekinoroji ifasha, cyangwa byibuze gukora kubitekerezo bidafite ishingiro muri rusange. Muri ibi bihe, tekereza gukoresha uburyo bwo kuganira.
Amahitamo
Nkuko amahitamo ashobora kunyuzwa kumurongo wamakuru cyangwa JavaScript, urashobora kongeramo izina ryamahitamo data-bs-
, nkuko biri data-bs-animation="{value}"
. Witondere guhindura ubwoko bwurubanza rwamahitamo kuva " ingamiya " kuri " kebab-urubanza " mugihe utambutsa amahitamo ukoresheje ibiranga amakuru. Kurugero, koresha data-bs-custom-class="beautifier"
aho data-bs-customClass="beautifier"
.
Nko muri Bootstrap 5.2.0, ibice byose bishyigikira igeragezwa ryibitse ryamakuru data-bs-config
rishobora kubamo ibice byoroshye nkibikoresho bya JSON. Mugihe ikintu gifite data-bs-config='{"delay":0, "title":123}'
nibiranga data-bs-title="456"
, agaciro kanyuma title
kazaba 456
kandi amakuru yihariye aranga agaciro katanzwe kuri data-bs-config
. Mubyongeyeho, amakuru ariho aranga arashobora kubika JSON indangagaciro nka data-bs-delay='{"show":0,"hide":150}'
.
sanitize
,,
sanitizeFn
hamwe
allowList
namahitamo ntashobora gutangwa ukoresheje ibiranga amakuru.
Izina | Andika | Mburabuzi | Ibisobanuro |
---|---|---|---|
allowList |
ikintu | Agaciro gasanzwe | Ikintu kirimo ibiranga byemewe na tagi. |
animation |
boolean | true |
Koresha CSS igenda ihinduka kuri popover. |
boundary |
umugozi, ikintu | 'clippingParents' |
Imipaka irenga imipaka ya popover (ikoreshwa gusa kuri popper yo gukumiraOverflow modifier). Mburabuzi, ni 'clippingParents' kandi irashobora kwakira HTMLElement yerekanwe (binyuze kuri JavaScript gusa). Kubindi bisobanuro reba popper's detectOverflow docs . |
container |
umugozi, ikintu, ibinyoma | false |
Ongeraho popover kubintu runaka. Urugero : container: 'body' . Ihitamo ningirakamaro cyane kuberako igufasha gushyira popover mugutemba kwinyandiko hafi yikintu gikurura - bizarinda popover kureremba kure yikintu gikurura mugihe idirishya rinini. |
content |
umugozi, ikintu, imikorere | '' |
Mburabuzi agaciro agaciro niba data-bs-content ikiranga kidahari. Niba imikorere yatanzwe, izahamagarwa hamwe this nibisobanuro byayo kuri element popover ifatanye. |
customClass |
umugozi, imikorere | '' |
Ongeraho amasomo kuri popover iyo yerekanwe. Menya ko aya masomo azongerwaho hiyongereyeho ibyiciro byose byerekanwe mubishusho. Ongeraho ibyiciro byinshi, ubitandukanye numwanya : 'class-1 class-2' . Urashobora kandi gutambutsa imikorere igomba gusubiza umurongo umwe urimo amazina yinyongera yinyongera. |
delay |
umubare, ikintu | 0 |
Gutinda kwerekana no guhisha popover (ms) - ntibikoreshwa muburyo bwintoki. Niba umubare watanzwe, gutinda gukoreshwa byombi guhisha / kwerekana. Imiterere yibintu ni : delay: { "show": 500, "hide": 100 } . |
fallbackPlacements |
umurongo, umurongo | ['top', 'right', 'bottom', 'left'] |
Sobanura ibyasubiwemo mugutanga urutonde rwibisobanuro (murwego rwo guhitamo). Kubindi bisobanuro reba imyitwarire ya Popper . |
html |
boolean | false |
Emerera HTML muri popover. Niba ari ukuri, tagi ya HTML muri popover title izerekanwa muri popover. Niba ari ibinyoma, innerText umutungo uzakoreshwa mugushyiramo ibiri muri DOM. Koresha inyandiko niba uhangayikishijwe n'ibitero bya XSS. |
offset |
umubare, umugozi, imikorere | [0, 0] |
Offset ya popover ugereranije nintego yayo. Urashobora gutambutsa umurongo muri data ibiranga hamwe na koma yatandukanijwe indangagaciro nka : data-bs-offset="10,20" . Iyo imikorere ikoreshwa mukumenya offset, yitwa hamwe nikintu kirimo icyerekezo cya popper, icyerekezo, hamwe na popper ikosora nkibitekerezo byayo byambere. Ikintu gikurura DOM node yatambutse nkimpaka ya kabiri. Igikorwa kigomba gusubiza umurongo hamwe nimibare ibiri: kunyerera , intera . Kubindi bisobanuro reba kuri popper ya offset . |
placement |
umugozi, imikorere | 'top' |
Nigute ushobora gushyira popover: imodoka, hejuru, hepfo, ibumoso, iburyo. Iyo auto bisobanuwe neza, bizagenda byerekeza kuri popover. Iyo imikorere ikoreshwa mukumenya aho ishyirwa, byitwa hamwe na popover DOM node nkibitekerezo byayo byambere hamwe na elementing DOM node nkibya kabiri. Imirongo this yashyizweho kuri popover urugero. |
popperConfig |
ubusa, ikintu, imikorere | null |
Guhindura Bootstrap isanzwe ya Popper config, reba iboneza rya Popper . Iyo imikorere ikoreshwa mugukora iboneza rya popper, byitwa hamwe nikintu kirimo Bootstrap isanzwe ya Popper. Iragufasha gukoresha no guhuza ibisanzwe hamwe nuburyo bwawe bwite. Imikorere igomba gusubiza ibintu byabugenewe kuri Popper. |
sanitize |
boolean | true |
Gushoboza cyangwa guhagarika isuku. Nibikora 'template' , 'content' kandi 'title' amahitamo azagira isuku. |
sanitizeFn |
ubusa, imikorere | null |
Hano urashobora gutanga imikorere yawe yisuku. Ibi birashobora kuba ingirakamaro niba uhisemo gukoresha isomero ryabigenewe kugirango ukore isuku. |
selector |
umugozi, ibinyoma | false |
Niba hatoranijwe uwatoranijwe, ibintu bya popover bizahabwa intego zagenwe. Mu myitozo, ibi bikoreshwa mugukoresha na popovers kubintu byongeweho imbaraga DOM ( jQuery.on inkunga). Reba iki kibazo nurugero rwamakuru . |
template |
umugozi | '<div class="popover" role="popover"><div class="popover-arrow"></div><div class="popover-inner"></div></div>' |
Shingiro HTML yo gukoresha mugihe uremye popover. Ibya popover title bizaterwa muri .popover-inner . .popover-arrow bizahinduka umwambi wa popover. Ikintu cyo gupfunyika hanze kigomba kugira urwego .popover na role="popover" . |
title |
umugozi, ikintu, imikorere | '' |
Mburabuzi Umutwe Agaciro niba title Ikiranga kidahari. Niba imikorere yatanzwe, izahamagarwa hamwe this nibisobanuro byayo kuri element popover ifatanye. |
trigger |
umugozi | 'hover focus' |
Uburyo popover ikururwa: kanda, uzenguruke, kwibanda, intoki. Urashobora gutsinda imbarutso nyinshi; kubatandukanya n'umwanya. 'manual' yerekana ko popover izaterwa na programme binyuze muri .popover('show') , .popover('hide') nuburyo .popover('toggle') ; agaciro ntigashobora guhuzwa nizindi mbarutso. 'hover' kubwonyine bizavamo popovers idashobora gukururwa hifashishijwe clavier, kandi igomba gukoreshwa gusa niba ubundi buryo bwo gutanga amakuru amwe kubakoresha clavier burahari. |
Ibiranga amakuru kuri popovers kugiti cye
Amahitamo ya popovers kugiti cye arashobora gusobanurwa muburyo bwo gukoresha ibiranga amakuru, nkuko byasobanuwe haruguru.
Gukoresha imikorere hamwepopperConfig
const popover = new bootstrap.Popover(element, {
popperConfig(defaultBsPopperConfig) {
// const newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Uburyo
Uburyo butajegajega ninzibacyuho
Inzira zose za API ntizihuza kandi zitangira inzibacyuho . Basubira kumuhamagara mugihe inzibacyuho itangiye ariko itararangira . Mubyongeyeho, uburyo bwo guhamagarira ibice byinzibacyuho bizirengagizwa .
Uburyo | Ibisobanuro |
---|---|
disable |
Kuraho ubushobozi bwa element ya popover kugirango yerekanwe. Popover izashobora kwerekanwa gusa niba yongeye gukora. |
dispose |
Hisha kandi usenye ikintu cya popover (Kuraho amakuru yabitswe kubintu bya DOM). Popovers ikoresha delegasiyo (yashizweho hakoreshejwe amahitamoselector ) ntishobora gusenywa kugiti cye kubintu bikomokaho . |
enable |
Itanga ikintu cya popover ubushobozi bwo kwerekanwa. Popovers ishoboye kubisanzwe. |
getInstance |
Uburyo buhamye butuma ubona urugero rwa popover rujyanye nibintu bya DOM. |
getOrCreateInstance |
Uburyo buhamye butuma ubona urugero rwa popover rujyanye nibintu bya DOM, cyangwa gukora bundi bushya mugihe bitatangijwe. |
hide |
Hisha ikintu cya popover. Garuka kumuhamagaye mbere yuko popover ihishwa mubyukuri (nukuvuga mbere yuko hidden.bs.popover ibyabaye biba). Ibi bifatwa nk "intoki" itera popover. |
setContent |
Itanga uburyo bwo guhindura ibiri muri popover nyuma yo gutangira. |
show |
Yerekana ikintu cya popover. Garuka kumuhamagara mbere yuko popover yerekanwe (nukuvuga mbere yuko shown.bs.popover ibyabaye biba). Ibi bifatwa nk "intoki" itera popover. Popovers ifite umutwe hamwe nibirimo byombi uburebure bwa zeru ntibigaragara. |
toggle |
Kuzuza ikintu cya popover. Garuka kumuhamagara mbere yuko popover yerekanwe cyangwa yihishe (nukuvuga mbere yuko ibyabaye shown.bs.popover cyangwa hidden.bs.popover ibyabaye bibaho). Ibi bifatwa nk "intoki" itera popover. |
toggleEnabled |
Kuzamura ubushobozi bwa popover yibintu kugirango yerekanwe cyangwa ihishe. |
update |
Kuvugurura umwanya wibintu bya popover. |
// getOrCreateInstance example
const popover = bootstrap.Popover.getOrCreateInstance('#example') // Returns a Bootstrap popover instance
// setContent example
myPopover.setContent({
'.popover-header': 'another title',
'.popover-body': 'another content'
})
setContent
bwemera
object
impaka, aho buri mutungo-urufunguzo numutoranya wemewe
string
mubishushanyo mbonera, kandi buri mutungo-agaciro ushobora kuba
string
|
element
|
function
|
null
Ibyabaye
Icyabaye | Ibisobanuro |
---|---|
hide.bs.popover |
Ibi birori birahita bisohoka mugihe uburyo hide bwurugero bwahamagawe. |
hidden.bs.popover |
Ibirori birukanwa mugihe popover yarangije guhishwa uyikoresha (azategereza ko inzibacyuho ya CSS irangira). |
inserted.bs.popover |
Ibirori birukanwe nyuma show.bs.popover yibyabaye mugihe icyitegererezo cya popover cyongewe kuri DOM. |
show.bs.popover |
Ibirori birasa ako kanya mugihe show urugero rwitwa. |
shown.bs.popover |
Ibirori birukanwa mugihe popover yakozwe igaragara kubakoresha (izategereza ko inzibacyuho ya CSS irangira). |
const myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', () => {
// do something...
})