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 yisunga isomero ryishyaka rya 3 Popper kugirango ihagarare. Ugomba gushyiramo popper.min.js mbere ya bootstrap.js cyangwa gukoresha
bootstrap.bundle.min.js
/bootstrap.bundle.js
irimo Popper kugirango popovers ikore! - Popovers isaba ibikoresho bya plugin nkibisabwa .
- 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.
Urugero: Gushoboza popovers ahantu hose
Uburyo bumwe bwo gutangiza popovers zose kurupapuro kwaba ari uguhitamo data-bs-toggle
kubiranga:
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
Urugero: Ukoresheje container
amahitamo
Mugihe ufite uburyo bumwe kubintu byababyeyi bibangamira popover, uzashaka kwerekana imigenzo container
kugirango HTML ya popover igaragara muri kiriya kintu aho.
var popover = new bootstrap.Popover(document.querySelector('.example-popover'), {
container: 'body'
})
Urugero
<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>
Ibyerekezo bine
Amahitamo ane arahari: hejuru, iburyo, hepfo, n'ibumoso. Icyerekezo kirimo indorerwamo mugihe ukoresheje Bootstrap muri 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>
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" 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'
})
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>
Sass
Ibihinduka
$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);
Ikoreshwa
Gushoboza popovers ukoresheje JavaScript:
var exampleEl = document.getElementById('example')
var 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
Amahitamo arashobora kunyuzwa kumurongo wamakuru cyangwa JavaScript. Kubiranga Ibyatanzwe, Ongeraho Ihitamo Izina Kuri data-bs-
, Nka Muri data-bs-animation=""
. Witondere guhindura ubwoko bwurubanza rwamazina kuva kuri camelCase kuri kebab-urubanza mugihe utambutsa amahitamo ukoresheje ibiranga amakuru. Kurugero, aho gukoresha data-bs-customClass="beautifier"
, koresha data-bs-custom-class="beautifier"
.
sanitize
,,
sanitizeFn
hamwe
allowList
namahitamo ntashobora gutangwa ukoresheje ibiranga amakuru.
Izina | Andika | Mburabuzi | Ibisobanuro |
---|---|---|---|
animation |
boolean | true |
Koresha CSS igenda ihinduka kuri popover |
container |
umugozi | ikintu | ibinyoma | false |
Ongeraho popover kubintu runaka. Urugero : |
content |
umugozi | ikintu | imikorere | '' |
Mburabuzi agaciro agaciro niba Niba imikorere yatanzwe, izahamagarwa hamwe |
delay |
umubare | ikintu | 0 |
Gutinda kwerekana no guhisha popover (ms) - ntabwo ikoreshwa muburyo bwintoki Niba umubare watanzwe, gutinda gukoreshwa byombi guhisha / kwerekana Imiterere yibintu ni: |
html |
boolean | false |
Shyiramo HTML muri popover. Niba ari ibinyoma, innerText umutungo uzakoreshwa mugushyiramo ibiri muri DOM. Koresha inyandiko niba uhangayikishijwe n'ibitero bya XSS. |
placement |
umugozi | imikorere | 'right' |
Nigute ushobora gushira popover - auto | hejuru | munsi | ibumoso | iburyo. Iyo imikorere ikoreshwa mukumenya aho ishyirwa, byitwa hamwe na popover DOM node nkibitekerezo byayo byambere hamwe na elementing DOM node nkibya kabiri. Imirongo |
selector |
umugozi | ibinyoma | false |
Niba hatoranijwe uwatoranijwe, ibintu bya popover bizahabwa intego zagenwe. Mu myitozo, ibi bikoreshwa mugushoboza HTML ifite imbaraga kugirango hongerwe popovers. Reba ibi nurugero rwamakuru . |
template |
umugozi | '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>' |
Shingiro HTML yo gukoresha mugihe uremye popover. Ibya popover Ibya popover
Ikintu cyo gupfunyika hanze kigomba kugira urwego |
title |
umugozi | ikintu | imikorere | '' |
Mburabuzi Umutwe Agaciro niba Niba imikorere yatanzwe, izahamagarwa hamwe |
trigger |
umugozi | 'click' |
Uburyo popover iterwa - kanda | hover | kwibanda | imfashanyigisho. Urashobora gutsinda imbarutso nyinshi; kubatandukanya n'umwanya. manual ntishobora guhuzwa nizindi mbarutso. |
fallbackPlacements |
array | ['top', 'right', 'bottom', 'left'] |
Sobanura ibyasubiwemo mugutanga urutonde rwibisobanuro (murwego rwo guhitamo). Kubindi bisobanuro reba imyitwarire ya popper |
boundary |
umugozi | element | 'clippingParents' |
Imipaka irenga imipaka ya popover (ikoreshwa gusa kuri popper yo gukumiraOverflow modifier). Mubusanzwe ni 'clippingParents' kandi irashobora kwemera HTMLElement (ukoresheje JavaScript gusa). Kubindi bisobanuro reba popper's detectOverflow docs . |
customClass |
umugozi | imikorere | '' |
Ongeraho amasomo kuri popover iyo yerekanwe. Menya ko aya masomo azongerwaho hiyongereyeho ibyiciro byose byerekanwe mubishusho. Ongeraho ibyiciro byinshi, ubitandukanye numwanya : Urashobora kandi gutambutsa imikorere igomba gusubiza umurongo umwe urimo amazina yinyongera. |
sanitize |
boolean | true |
Gushoboza cyangwa guhagarika isuku. Nibikora 'template' , 'content' kandi 'title' amahitamo azagira isuku. Reba igice cyisuku mubyangombwa byacu bya JavaScript . |
allowList |
ikintu | Agaciro gasanzwe | Ikintu kirimo ibiranga byemewe na tagi |
sanitizeFn |
null | imikorere | null |
Hano urashobora gutanga imikorere yawe yisuku. Ibi birashobora kuba ingirakamaro niba uhisemo gukoresha isomero ryabigenewe kugirango ukore isuku. |
offset |
array | umugozi | imikorere | [0, 8] |
Offset ya popover ugereranije nintego yayo. Urashobora gutambutsa umurongo muri data ibiranga hamwe na koma yatandukanijwe indangagaciro nka: 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 : . Kubindi bisobanuro reba kuri popper ya offset . |
popperConfig |
null | 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 idasanzwe ya Popper. Iragufasha gukoresha no guhuza ibisanzwe hamwe nuburyo bwawe bwite. Imikorere igomba gusubiza ibintu byabugenewe kuri Popper. |
Ibiranga amakuru kuri popovers kugiti cye
Amahitamo ya popovers kugiti cye arashobora gusobanurwa muburyo bwo gukoresha ibiranga amakuru, nkuko byasobanuwe haruguru.
Gukoresha imikorere hamwepopperConfig
var popover = new bootstrap.Popover(element, {
popperConfig: function (defaultBsPopperConfig) {
// var 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 .
kwerekana
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.
myPopover.show()
kwihisha
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.
myPopover.hide()
guhinduranya
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.
myPopover.toggle()
guta
Hisha kandi usenye ikintu cya popover (Kuraho amakuru yabitswe kubintu bya DOM). Popovers ikoresha delegasiyo (yashizweho hakoreshejwe amahitamoselector
) ntishobora gusenywa kugiti cye kubintu bikomokaho .
myPopover.dispose()
Gushoboza
Itanga ikintu cya popover ubushobozi bwo kwerekanwa. Popovers ishoboye kubisanzwe.
myPopover.enable()
guhagarika
Kuraho ubushobozi bwa element ya popover kugirango yerekanwe. Popover izashobora kwerekanwa gusa niba yongeye gukora.
myPopover.disable()
Guhindura
Kuzamura ubushobozi bwa popover yibintu kugirango yerekanwe cyangwa ihishe.
myPopover.toggleEnabled()
kuvugurura
Kuvugurura umwanya wibintu bya popover.
myPopover.update()
Kubona
Uburyo buhamye butuma ubona urugero rwa popover rujyanye nibintu bya DOM
var exampleTriggerEl = document.getElementById('example')
var popover = bootstrap.Popover.getInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
GetOrCreateInstance
Uburyo buhamye butuma ubona urugero rwa popover rujyanye nibintu bya DOM, cyangwa gukora bundi bushya mugihe bitatangijwe
var exampleTriggerEl = document.getElementById('example')
var popover = bootstrap.Popover.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
Ibyabaye
Ubwoko bwibyabaye | Ibisobanuro |
---|---|
kwerekana.bs | Ibirori birasa ako kanya mugihe show urugero rwitwa. |
yerekanwe.bs | Ibirori birukanwa mugihe popover yakozwe igaragara kubakoresha (izategereza ko inzibacyuho ya CSS irangira). |
guhisha.bs | Ibi birori birahita bisohoka mugihe uburyo hide bwurugero bwahamagawe. |
bihishe.bs | Ibirori birukanwa mugihe popover yarangije guhishwa uyikoresha (azategereza ko inzibacyuho ya CSS irangira). |
Byinjijwe.bs | Ibirori birukanwe nyuma show.bs.popover yibyabaye mugihe icyitegererezo cya popover cyongewe kuri DOM. |
var myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
// do something...
})