Bafutsana
Litokomane le mehlala ea ho kenyelletsa li-popovers tsa Bootstrap, joalo ka tse fumanehang ho iOS, nthong efe kapa efe sebakeng sa hau sa marang-rang.
Kakaretso
Lintho tseo u lokelang ho li tseba ha u sebelisa plugin ea popover:
- Popovers e itšetlehile ka laeborari ea mokha oa boraro ea Popper bakeng sa maemo. U tlameha ho kenyelletsa popper.min.js pele ho bootstrap.js kapa sebelisa
bootstrap.bundle.min.js
/bootstrap.bundle.js
e nang le Popper e le hore popovers e sebetse! - Li-Popovers li hloka plugin ea tooltip e le ho itšetleha.
- Li-Popovers li khetha ho kena ka mabaka a ts'ebetso, kahoo u tlameha ho li qala ka bouena .
- Bolelele ba zero
title
lecontent
litekanyetso li ke ke tsa bontša popover. - Hlakisa
container: 'body'
ho qoba ho fana ka mathata ka likarolo tse rarahaneng (joalo ka lihlopha tsa rona tsa ho kenya, lihlopha tsa likonopo, joalo-joalo). - Ho kenya li-popover linthong tse patiloeng ho ke ke ha sebetsa.
- Li-Popovers tsa
.disabled
kapadisabled
li-elementi li tlameha ho hlahisoa holim'a karolo ea wrapper. - Ha li ts'oaroa ho tsoa ho li-ankora tse pota-potileng mela e mengata, li-popover li tla behoa bohareng ba bophara ba li-ankora. Sebelisa
.text-nowrap
ho hao<a>
ho qoba boitšoaro bona. - Li-Popovers li tlameha ho patoa pele likarolo tsa tsona tse tsamaellanang li tlosoa ho DOM.
- Popovers e ka hlahisoa ka lebaka la ntho e ka hare ho moriti oa DOM.
prefers-reduced-motion
potso ea media. Sheba karolo e
fokolitsoeng ea motsamao oa litokomane tsa phihlello ea rona .
Tsoela pele ho bala ho bona hore na popover e sebetsa joang ka mehlala e meng.
Mohlala: Lumella li-popovers hohle
Mokhoa o mong oa ho qala li-popovers tsohle leqepheng e tla ba ho li khetha ho latela data-bs-toggle
semelo sa tsona:
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
Mohlala: Ho sebelisa container
khetho
Ha u e-na le mekhoa e meng ea ntho ea motsoali e sitisang popover, u tla batla ho hlalosa tloaelo container
e le hore HTML ea popover e hlahe ka har'a ntho eo ho e-na le hoo.
var popover = new bootstrap.Popover(document.querySelector('.example-popover'), {
container: 'body'
})
Mohlala
<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>
Litsela tse 'ne
Ho na le likhetho tse 'nè: holimo, ho le letona, ka tlase, le ho le letšehali. Litaelo li bonts'oa ha u sebelisa Bootstrap ho 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>
Tlosa ho tobetsa e latelang
Sebelisa focus
seqhutsu ho leleka li-popovers ha mosebelisi a tobetsa ntho e latelang e fapaneng le ea toggle element.
Ho hlokahala letšoao le ikhethileng bakeng sa ho penya-ha-e latelang
Bakeng sa boits'oaro bo nepahetseng ba sebatli le sethala, o tlameha ho sebelisa tag <a>
, eseng<button>
tag, hape o tlameha ho kenyelletsa tabindex
tšobotsi.
<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'
})
Lintho tse holofetseng
Lintho tse nang le disabled
tšobotsi ha li sebelisane, ho bolelang hore basebelisi ba ke ke ba li sutumelletsa kapa ba li tobetse ho etsa hore popover (kapa tooltip). Joalo ka mokhoa oa ho sebetsa, o tla batla ho tsosa popover ho tsoa ho sephutheloana <div>
kapa <span>
, e etselitsoeng hore keyboard e tsepamise maikutlo ho sebelisoa tabindex="0"
.
Bakeng sa li-triggers tsa popover tse nang le bokooa, u kanna ua khetha data-bs-trigger="hover focus"
hore popover e hlahe e le maikutlo a hanghang ho basebelisi ba hau kaha ba kanna ba se lebelle ho tobetsa ntho e holofetseng.
<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
Lintho tse fapaneng
$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);
Tšebeliso
Lumella li-popover ka JavaScript:
var exampleEl = document.getElementById('example')
var popover = new bootstrap.Popover(exampleEl, options)
Ho etsa hore popover e sebetse bakeng sa basebelisi ba keyboard le theknoloji e thusang
Ho lumella basebelisi ba keyboard ho kenya li-popovers tsa hau, u lokela ho li kenya feela ho likarolo tsa HTML tseo ka tloaelo li shebaneng le keyboard le ho sebelisana (joalo ka likhokahano kapa taolo ea foromo). Leha likarolo tsa HTML (tse kang <span>
s) li ka tsepamisoa maikutlo ka ho eketsa tabindex="0"
tšobotsi, sena se tla eketsa li-tab tse ka khopisang le tse ferekanyang linthong tse sa sebetseng bakeng sa basebelisi ba keyboard, 'me mahlale a mangata a thusang hajoale ha a phatlalatse litaba tsa popover maemong ana. . Ho phaella moo, u se ke ua itšetleha feela ka hover
hore ke mohloli oa li-popovers tsa hau, kaha sena se tla etsa hore ho se khonehe ho qalisa basebelisi ba keyboard.
Leha o ka kenya HTML e ruileng, e hlophisitsoeng ka har'a popover ka html
khetho, re khothaletsa ka matla hore u qobe ho eketsa bongata bo bongata ba litaba. Tsela eo popovers e sebetsang ka eona hajoale ke hore, hang ha e se e bonts'itsoe, litaba tsa bona li hokahane le ntho e qalang ka aria-describedby
semelo. Ka lebaka leo, litaba tsa popover kaofela li tla phatlalatsoa ho basebelisi ba theknoloji e thusang e le molatsoana o le mong o molelele o sa sitisoeng.
Ho feta moo, leha ho ka khoneha ho kenyelletsa li-control tse sebetsanang (joalo ka likarolo tsa sebopeho kapa likhokahano) ho popover ea hau (ka ho kenyelletsa lintlha tsena ho allowList
litšoaneleho le li-tag tse lumelletsoeng), hlokomela hore hajoale popover ha e laole tatellano ea ho tsepamisa maikutlo ho keyboard. Ha mosebelisi oa keyboard a bula popover, ho tsepamisitsoe maikutlo ho ntho e qalang, 'me joalo ka ha popover hangata e sa latele sesosa hanghang sebopehong sa tokomane, ha ho na tiiso ea hore ho ea pele/ho hatella.TABe tla tsamaisa mosebelisi oa keyboard ho popover ka boeona. Ka bokhuts'oane, ho kenya li-control tse sebetsang ho popover ho ka etsa hore litsamaiso tsena li se fumanehe / li se ke tsa sebelisoa bakeng sa basebelisi ba keyboard le basebelisi ba mahlale a thusang, kapa bonyane ho etsa tatellano e sa utloahaleng ea ho tsepamisa maikutlo. Maemong ana, nahana ka ho sebelisa modal dialog ho e-na le hoo.
Dikgetho
Likhetho li ka fetisoa ka lintlha tsa data kapa JavaScript. Bakeng sa litšobotsi tsa data, kenya lebitso la khetho ho data-bs-
, joalo ka data-bs-animation=""
. Etsa bonnete ba hore o fetola mofuta oa nyeoe ea lebitso la khetho ho tloha ho camelCase ho ea ho kebab-case ha o fetisa likhetho ka litšobotsi tsa data. Ka mohlala, ho e-na le ho sebelisa data-bs-customClass="beautifier"
, sebelisa data-bs-custom-class="beautifier"
.
sanitize
,
sanitizeFn
, le
allowList
likhetho li ke ke tsa fanoa ho sebelisoa litšobotsi tsa data.
Lebitso | Mofuta | Ea kamehla | Tlhaloso |
---|---|---|---|
animation |
boolean | true |
Kenya phetoho ea CSS fade ho popover |
container |
khoele | ntho | bohata | false |
E eketsa popover ho element e itseng. Mohlala |
content |
khoele | ntho | tshebetso | '' |
Boleng ba litaba bo ka rekoang haeba Haeba ts'ebetso e fanoe, e tla bitsoa ka |
delay |
nomoro | ntho | 0 |
Ho lieha ho bonts'a le ho pata popover (ms) - ha e sebetse ho mofuta oa mochini oa ho qala Haeba nomoro e fanoe, ho lieha ho sebelisoa ho pata/show ka bobeli Sebopeho sa ntho ke: |
html |
boolean | false |
Kenya HTML ho popover. Haeba e le leshano, innerText thepa e tla sebelisoa ho kenya litaba ho DOM. Sebelisa mongolo haeba u tšoenyehile ka litlhaselo tsa XSS. |
placement |
khoele | tshebetso | 'right' |
Mokhoa oa ho beha popover - auto | holimo | tlase | le letšehali | hantle. Ha ts'ebetso e sebelisoa ho fumana sebaka sa ho beoa, e bitsoa le node ea popover DOM e le khang ea eona ea pele le ntho e qalang ea DOM node e le ea bobeli. Boemo |
selector |
khoele | bohata | false |
Haeba ho fanoe ka khetho, lintho tsa popover li tla abeloa ho sepheo se boletsoeng. Ha e le hantle, sena se sebelisetsoa ho nolofalletsa litaba tsa HTML tse matla hore li eketsoe ke popover. Bona sena le mohlala o rutang . |
template |
khoele | '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>' |
HTML ea mantlha eo u ka e sebelisang ha u theha popover. Li-popover li Li-popover li
Karolo e ka ntle ea wrapper e lokela ho ba le |
title |
khoele | ntho | tshebetso | '' |
Boleng ba sehlooho sa kamehla haeba Haeba ts'ebetso e fanoe, e tla bitsoa ka |
trigger |
khoele | 'click' |
Popover e qala joang - tlanya | hloella | tsepamisa | tataiso. U ka 'na ua fetisa li-triggers tse ngata; di arole ka sebaka. manual e ke ke ea kopanngoa le ntho leha e le efe e qalang. |
fallbackPlacements |
array | ['top', 'right', 'bottom', 'left'] |
Hlalosa lipehelo tsa morao-rao ka ho fana ka lethathamo la libaka tse behiloeng ka tatellano (ho ea ka khetho). Bakeng sa tlhaiso-leseling e batsi, sheba litokomane tsa Popper tsa boitšoaro |
boundary |
khoele | element | 'clippingParents' |
Moeli o thibelang ho phalla ha metsi (o sebetsa feela ho Popper's preventOverflow modifier). Ka mokhoa o 'clippingParents' ikhethileng ke 'me e ka amohela tšupiso ea HTMLElement (ka JavaScript feela). Ho fumana lintlha tse ling, sheba ho Popper's detectOverflow docs . |
customClass |
khoele | tshebetso | '' |
Kenya litlelase ho popover ha e bontšoa. Hlokomela hore litlelase tsena li tla eketsoa ho kenyelletsa litlelase life kapa life tse boletsoeng template. Ho eketsa lihlopha tse ngata, li arole ka libaka: U ka fetisa tšebetso e lokelang ho khutlisa khoele e le 'ngoe e nang le mabitso a sehlopha sa tlatsetso. |
sanitize |
boolean | true |
Lumella kapa u tima tsamaiso ea sanitization. Haeba e kentsoe 'template' , 'content' 'me 'title' likhetho li tla hloekisoa. Sheba karolo ea sanitizer litokomaneng tsa rona tsa JavaScript . |
allowList |
ntho | Boleng ba kamehla | Ntho e nang le litšobotsi le li-tag tse lumelletsoeng |
sanitizeFn |
null | tshebetso | null |
Mona o ka fana ka ts'ebetso ea hau ea sanitize. Sena se ka ba molemo haeba u khetha ho sebelisa laebrari e inehetseng ho etsa bohloeki. |
offset |
sehlopha | khoele | tshebetso | [0, 8] |
Phetoho ea popon e ipapisitse le sepheo sa eona. O ka fetisa khoele ho litšobotsi tsa data tse nang le boleng bo arohaneng ba comma joalo ka: Ha ts'ebetso e sebelisoa ho fumana qeto, e bitsoa ka ntho e nang le popper placement, reference, le popper rects e le khang ea eona ea pele. The triggering element DOM node e fetisitsoe e le khang ea bobeli. Mosebetsi o tlameha ho khutlisa sehlopha se nang le linomoro tse peli: . Ho fumana lintlha tse ling, sheba ho Popper's offset docs . |
popperConfig |
null | ntho | tshebetso | null |
Ho fetola tlhophiso ea kamehla ea Bootstrap ea Popper, bona tlhophiso ea Popper . Ha ts'ebetso e sebelisoa ho theha tlhophiso ea Popper, e bitsoa ka ntho e nang le tlhophiso ea kamehla ea Bootstrap ea Popper. E u thusa ho sebelisa le ho kopanya ea kamehla le tlhophiso ea hau. Ts'ebetso e tlameha ho khutlisa ntho e hlophisitsoeng bakeng sa Popper. |
Litšobotsi tsa data bakeng sa li-popovers ka bomong
Likhetho bakeng sa li-popovers ka bomong li ka hlalosoa ka tšebeliso ea litšobotsi tsa data, joalo ka ha ho hlalositsoe ka holimo.
Ho sebelisa ts'ebetso lepopperConfig
var popover = new bootstrap.Popover(element, {
popperConfig: function (defaultBsPopperConfig) {
// var newPopperConfig = {...}
// use defaultBsPopperConfig if needed...
// return newPopperConfig
}
})
Mekhoa
Mekhoa ea Asynchronous le liphetoho
Mekhoa eohle ea API ha e- synchronous 'me e qala phetoho . Ba khutlela ho motho ea letselitseng hang ha phetoho e qala empa pele e fela . Ho feta moo, mohala oa mokhoa ho karolo ea phetoho o tla hlokomolohuoa .
Sheba litokomane tsa rona tsa JavaScript bakeng sa lintlha tse ling .
bontsha
E hlahisa poover ea element. E khutlela ho ea letselitseng pele popover e bonts'oa (ke hore pele shown.bs.popover
ketsahalo e etsahala). Sena se nkuoa e le "manual" e tsosang popo. Li-Popovers tseo sehlooho le litaba tsa tsona li leng bolelele ba lefela ha ho mohla li hlahisoang.
myPopover.show()
pata
E pata popo ea lintho. E khutlela ho ea letselitseng pele popover e patiloe (ke hore pele hidden.bs.popover
ketsahalo e etsahala). Sena se nkuoa e le "manual" e tsosang popo.
myPopover.hide()
toggle
E fetola popover ea element. E khutlela ho ea letselitseng pele popover e bonts'oa kapa e patiloe (ke hore pele ketsahalo shown.bs.popover
kapa hidden.bs.popover
ketsahalo e etsahala). Sena se nkuoa e le "manual" e tsosang popo.
myPopover.toggle()
lahla
E pata le ho senya popover ea element (E tlosa data e bolokiloeng ho element ea DOM). Li-Popovers tse sebelisang moifo (tse entsoeng ho sebelisoa khetho selector
) li ke ke tsa senngoa ka bonngoe ho latela likarolo tse qalang.
myPopover.dispose()
nolofalletsa
E fa element's popover bokhoni ba ho bonts'a. Li-Popovers li lumelloa ka mokhoa oa kamehla.
myPopover.enable()
tima
E tlosa bokhoni ba ho hlahisa popover ea element. Popover e tla bonts'oa feela ha e buletsoe hape.
myPopover.disable()
toggleEnabled
E fetola bokhoni ba popover ea element hore e bontšoe kapa e patehe.
myPopover.toggleEnabled()
nchafatsa
E kaonefatsa boemo ba elemente popover.
myPopover.update()
getInstance
Mokhoa o tsitsitseng o o lumellang ho fumana mohlala oa popover o amanang le ntho ea DOM
var exampleTriggerEl = document.getElementById('example')
var popover = bootstrap.Popover.getInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
getOrCreateInstance
Mokhoa o tsitsitseng o o lumellang ho fumana mohlala oa popover o amanang le ntho ea DOM, kapa u thehe e ncha haeba e sa qalisoa.
var exampleTriggerEl = document.getElementById('example')
var popover = bootstrap.Popover.getOrCreateInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
Liketsahalo
Mofuta oa ketsahalo | Tlhaloso |
---|---|
bonts'a.bs.popover | Ketsahalo ena e tuka hang hang ha show mokhoa oa mohlala o bitsoa. |
bontshitsweng.bs.popover | Ketsahalo ena e lelekoa ha popover e se e bonahala ho mosebelisi (e tla emela hore liphetoho tsa CSS li phethehe). |
pata.bs.popover | Ketsahalo ena e lelekoa hang hang ha hide mokhoa oa mohlala o bitsoa. |
patiloeng.bs.popover | Ketsahalo ena e ts'oaroa ha popover e qetile ho patoa ho mosebelisi (e tla emela hore liphetoho tsa CSS li phethehe). |
kentse.bs.popover | Ketsahalo ena e lelekoa kamora show.bs.popover ketsahalo ea ha template ea popover e kentsoe ho DOM. |
var myPopoverTrigger = document.getElementById('myPopover')
myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
// do something...
})