Toasts
Thawb cov ntawv ceeb toom rau koj cov neeg tuaj saib nrog toast, lub teeb yuag thiab yooj yim customizable ceeb toom cov lus.
Toasts yog cov ntawv ceeb toom teeb pom kev zoo tsim los ua cov ntawv ceeb toom thawb uas tau nrov los ntawm cov xov tooj ntawm tes thiab desktop operating systems. Lawv tau tsim nrog flexbox, yog li lawv yooj yim rau kev sib dhos thiab txoj haujlwm.
Txheej txheem cej luam
Tej yam uas yuav tsum paub thaum siv lub toast plugin:
- Yog tias koj tab tom tsim peb JavaScript los ntawm qhov chaw, nws xav tau
util.js
. - Toasts yog opt-in rau kev ua tau zoo vim li cas, yog li koj yuav tsum pib lawv tus kheej .
- Toasts yuav cia li nkaum yog tias koj tsis qhia
autohide: false
.
Piv txwv
Basic
Txhawm rau txhawb nqa cov toasts uas tau nthuav dav thiab kwv yees tau, peb pom zoo kom lub taub hau thiab lub cev. Toast headers siv display: flex
, tso cai yooj yim sib dhos ntawm cov ntsiab lus ua tsaug rau peb cov paj thiab cov khoom siv flexbox.
Toasts yog hloov tau raws li koj xav tau thiab muaj tsawg heev xav tau markup. Qhov tsawg kawg nkaus, peb xav tau ib lub ntsiab lus kom muaj koj cov ntsiab lus "toasted" thiab txhawb kom lub pob tso tawm.
Translucent
Toasts yog me ntsis translucent, ib yam nkaus, yog li lawv sib tov txhua yam uas lawv yuav tshwm sim. Rau cov browsers uas txhawb nqa cov backdrop-filter
cuab yeej CSS, peb tseem yuav sim ua kom pom cov ntsiab lus hauv qab toast.
stacking
Thaum koj muaj ntau yam toasts, peb ua li ntawd rau vertiaclly stacking lawv nyob rau hauv ib tug nyeem tau.
Qhov chaw
Muab cov toasts nrog kev cai CSS raws li koj xav tau. Sab saum toj txoj cai feem ntau yog siv rau kev ceeb toom, ib yam li sab saum toj nruab nrab. Yog tias koj tsuas yog yuav tsum tau qhia ib qho toast ib zaug, muab cov qauv tso cai rau ntawm .toast
.
Rau cov tshuab uas tsim cov ntawv ceeb toom ntxiv, xav txog kev siv cov khoom qhwv kom lawv tuaj yeem yooj yim pawg.
Koj tuaj yeem tau txais kev zoo nkauj nrog cov khoom siv flexbox los ua kom cov toasts horizontally thiab / lossis vertically.
Kev siv tau
Toasts yog npaj los cuam tshuam me me rau koj cov neeg tuaj saib lossis cov neeg siv, yog li txhawm rau pab cov neeg uas muaj cov ntawv nyeem thiab cov thev naus laus zis zoo sib xws, koj yuav tsum qhwv koj cov toasts hauv ib aria-live
cheeb tsam . Kev hloov pauv rau thaj chaw nyob (xws li txhaj tshuaj / hloov kho cov khoom noj toast) tau tshaj tawm los ntawm cov neeg siv tshuaj ntsuam yam tsis tas yuav txav tus neeg siv lub hom phiaj lossis cuam tshuam rau tus neeg siv. Tsis tas li ntawd, suav nrog aria-atomic="true"
kom paub meej tias tag nrho cov toast yog ib txwm tshaj tawm raws li ib qho (atomic) unit, es tsis tshaj tawm qhov hloov pauv (uas tuaj yeem ua rau muaj teeb meem yog tias koj tsuas yog hloov kho ib feem ntawm cov toast cov ntsiab lus, lossis yog tias tso saib tib lub toast cov ntsiab lus ntawm lub sijhawm tom qab ntawd). Yog tias cov ntaub ntawv xav tau yog qhov tseem ceeb rau cov txheej txheem, piv txwv li rau ib daim ntawv teev cov kev ua yuam kev hauv ib daim ntawv, ces siv cov lus ceeb toom .tsis yog toast.
Nco ntsoov tias thaj av nyob yuav tsum muaj nyob rau hauv cov cim ua ntej lub toast yog tsim los yog hloov tshiab. Yog tias koj dynamically tsim ob qho tib si tib lub sijhawm thiab txhaj rau hauv nplooj ntawv, lawv feem ntau yuav tsis raug tshaj tawm los ntawm cov cuab yeej pabcuam.
Koj kuj yuav tsum tau hloov kho role
thiab aria-live
qib nyob ntawm cov ntsiab lus. Yog tias nws yog cov lus tseem ceeb xws li kev ua yuam kev, siv role="alert" aria-live="assertive"
, txwv tsis pub siv cov role="status" aria-live="polite"
cwj pwm.
Raws li cov ntsiab lus koj tab tom nthuav tawm cov kev hloov pauv, nco ntsoov hloov kho lub delay
sijhawm kom ntseeg tau tias tib neeg muaj sijhawm txaus los nyeem cov toast.
Thaum siv autohide: false
, koj yuav tsum ntxiv khawm kaw kom tso cai rau cov neeg siv tshem tawm cov toast.
JavaScript cwj pwm
Kev siv
Pib pib toasts ntawm JavaScript:
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 | Thov ib qho CSS ploj mus rau qhov toast |
autohide | boolean | muaj tseeb | Nws pib zais lub toast |
ncua | tus lej | 500 |
Ncua zais qhov ci ci (ms) |
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 .
$().toast(options)
Txuas lub toast handler rau ib qho khoom sau.
.toast('show')
Tshaj tawm ib qho khoom ci ci. Rov qab mus rau tus neeg hu ua ntej qhov toast tau tshwm sim tiag tiag (piv txwv li ua ntej qhov shown.bs.toast
xwm txheej tshwm sim). Koj yuav tsum manually hu rau txoj kev no, es tsis txhob koj toast yuav tsis qhia.
.toast('hide')
Hide ib qho khoom ci ci. Rov qab mus rau tus neeg hu ua ntej qhov toast tau muab zais tiag tiag (piv txwv li ua ntej qhov hidden.bs.toast
xwm txheej tshwm sim). Koj yuav tsum manually hu rau txoj kev no yog tias koj ua autohide
rau false
.
.toast('dispose')
Hide ib qho khoom ci ci. Koj lub ncuav yuav nyob twj ywm ntawm DOM tab sis yuav tsis tshwm sim ntxiv lawm.
Cov xwm txheej
Hom xwm txheej | Kev piav qhia |
---|---|
show.bs.toast | Qhov xwm txheej no tua hluav taws tam sim ntawd thaum show hu ua piv txwv. |
ua.bs.toast | Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub ci ci tau pom rau tus neeg siv. |
hide.bs.toast | Qhov xwm txheej no raug rho tawm haujlwm tam sim ntawd thaum hide hu ua piv txwv txoj kev. |
zais.bs.toast | Qhov kev tshwm sim no raug rho tawm haujlwm thaum lub toast tiav lawm muab zais los ntawm tus neeg siv. |