Toost
Shyira amatangazo kubashyitsi bawe hamwe na toast, umutwaro woroshye kandi byoroshye guhinduranya ubutumwa.
Toast ni amatangazo yoroheje yagenewe kwigana amatangazo yo gusunika yakunzwe na sisitemu y'imikorere ya mobile na desktop. Zubatswe na flexbox, biroroshye rero guhuza no guhagarara.
Incamake
Ibintu ugomba kumenya mugihe ukoresheje plugin ya toast:
- Toast irahitamo kubwimpamvu zikorwa, ugomba rero kubitangiza wenyine .
- Toast izahita ihisha niba udasobanuye
autohide: false
.
prefers-reduced-motion
nibibazo byitangazamakuru. Reba igice
cyagabanijwe cyicyiciro cyibisobanuro byacu .
Ingero
Shingiro
Kugirango dushishikarize toast yagutse kandi iteganijwe, turasaba umutwe numubiri. Imitwe ya toast ikoresha display: flex
, yemerera guhuza byoroshye ibikubiyemo dukesha margin na flexbox yingirakamaro.
Toast iroroshye guhinduka nkuko ubikeneye kandi ifite ibimenyetso bike bisabwa. Nibura, dukeneye ikintu kimwe kugirango gikubiyemo ibintu "byuzuye" kandi dushishikarize cyane buto yo kwirukana.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
Baho
Kanda buto hepfo kugirango werekane toast (ihagaze hamwe nibikorwa byacu mugice cyo hepfo yiburyo) yahishe muburyo budasanzwe .hide
.
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
<div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
Birasobanutse
Toast irasobanutse gato kugirango ihuze nibiri munsi yabyo.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
Gushyira hamwe
Urashobora gutondekanya toasti uyiziritse mubikoresho bya toast, bizongera byongeweho umwanya.
<div class="toast-container">
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
See? Just like this.
</div>
</div>
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">2 seconds ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Heads up, toasts will stack automatically
</div>
</div>
</div>
Ibirimo
Hindura toast yawe ukuraho ibice, uyihindure hamwe nibikorwa , cyangwa wongeyeho ikimenyetso cyawe. Hano twashizeho toast yoroshye mugukuraho ibisanzwe .toast-header
, twongeraho igishushanyo cyihishe mugushushanya kwa Bootstrap , no gukoresha ibikoresho bya flexbox kugirango duhindure imiterere.
<div class="toast align-items-center" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
Hello, world! This is a toast message.
</div>
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
Ubundi, urashobora kandi kongeramo ubugenzuzi nibindi bikoresho kuri toast.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body">
Hello, world! This is a toast message.
<div class="mt-2 pt-2 border-top">
<button type="button" class="btn btn-primary btn-sm">Take action</button>
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="toast">Close</button>
</div>
</div>
</div>
Ibara
Kubaka kurugero ruvuzwe haruguru, urashobora gukora ibara ritandukanye rya toast hamwe nibara ryacu hamwe nibikorwa byingenzi. Hano twongeyeho .bg-primary
no .text-white
kuri .toast
, hanyuma twongera .btn-close-white
kuri buto yacu yegeranye. Kuburyo bworoshye, dukuraho imipaka isanzwe hamwe .border-0
.
<div class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
Hello, world! This is a toast message.
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
Gushyira
Shira toast hamwe na CSS yihariye nkuko ubikeneye. Hejuru iburyo bukoreshwa kenshi kubimenyeshwa, nkuko biri hejuru. Niba ugiye gusa kwerekana toast imwe icyarimwe, shyira uburyo bwo guhagarara neza kuri .toast
.
<form>
<div class="mb-3">
<label for="selectToastPlacement">Toast placement</label>
<select class="form-select mt-2" id="selectToastPlacement">
<option value="" selected>Select a position...</option>
<option value="top-0 start-0">Top left</option>
<option value="top-0 start-50 translate-middle-x">Top center</option>
<option value="top-0 end-0">Top right</option>
<option value="top-50 start-0 translate-middle-y">Middle left</option>
<option value="top-50 start-50 translate-middle">Middle center</option>
<option value="top-50 end-0 translate-middle-y">Middle right</option>
<option value="bottom-0 start-0">Bottom left</option>
<option value="bottom-0 start-50 translate-middle-x">Bottom center</option>
<option value="bottom-0 end-0">Bottom right</option>
</select>
</div>
</form>
<div aria-live="polite" aria-atomic="true" class="bg-dark position-relative bd-example-toasts">
<div class="toast-container position-absolute p-3" id="toastPlacement">
<div class="toast">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
</div>
Kuri sisitemu zitanga ibisobanuro byinshi, tekereza gukoresha ikintu cyo gupfunyika kugirango zishobore gutondeka byoroshye.
<div aria-live="polite" aria-atomic="true" class="position-relative">
<!-- Position it: -->
<!-- - `.toast-container` for spacing between toasts -->
<!-- - `.position-absolute`, `top-0` & `end-0` to position the toasts in the upper right corner -->
<!-- - `.p-3` to prevent the toasts from sticking to the edge of the container -->
<div class="toast-container position-absolute top-0 end-0 p-3">
<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
See? Just like this.
</div>
</div>
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">2 seconds ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Heads up, toasts will stack automatically
</div>
</div>
</div>
</div>
Urashobora kandi kubona ibintu byiza hamwe na flexbox yingirakamaro kugirango uhuze toast itambitse kandi / cyangwa uhagaritse.
<!-- Flexbox container for aligning the toasts -->
<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center w-100">
<!-- Then put toasts within -->
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
</div>
Kuboneka
Toast igenewe kuba intambamyi ntoya kubasuye cyangwa abakoresha, kugirango rero ufashe abafite abasomyi ba ecran hamwe nikoranabuhanga risa naryo rifasha, ugomba kuzinga toast yawe aria-live
mukarere . Impinduka mukarere gatuye (nko gutera inshinge / kuvugurura ibice bya toast) birahita bitangazwa nabasomyi ba ecran bitabaye ngombwa ko wimura icyerekezo cyumukoresha cyangwa ubundi guhagarika umukoresha. Byongeye kandi, shyiramo aria-atomic="true"
kwemeza ko toast yose ihora itangazwa nkigice kimwe (atome), aho gutangaza gusa ibyahinduwe (bishobora kugutera ibibazo uramutse uvuguruye gusa igice cyibirimo, cyangwa niba ugaragaza ibintu bimwe bya toast mugihe cyakera mugihe). Niba amakuru akenewe ari ingenzi kubikorwa, urugero kurutonde rwamakosa muburyo, hanyuma ukoreshe ibice byo kumenyeshaaho toast.
Menya ko akarere kazima gakeneye kuba mubimenyetso mbere yuko toast ikorwa cyangwa ivugururwa. Niba ubyara umusaruro byombi icyarimwe hanyuma ukabitera kurupapuro, mubisanzwe ntabwo bizatangazwa nikoranabuhanga rifasha.
Ugomba kandi guhuza role
urwego aria-live
nurwego ukurikije ibirimo. Niba ari ubutumwa bwingenzi nkikosa, koresha role="alert" aria-live="assertive"
, ubundi ukoreshe role="status" aria-live="polite"
ibiranga.
Nkibirimo ugaragaza impinduka, menya neza kuvugurura delay
igihe kugirango abakoresha babone umwanya uhagije wo gusoma toast.
<div class="toast" role="alert" aria-live="polite" aria-atomic="true" data-bs-delay="10000">
<div role="alert" aria-live="assertive" aria-atomic="true">...</div>
</div>
Mugihe ukoresha autohide: false
, ugomba kongeramo buto yegeranye kugirango wemerere abakoresha kwirukana toast.
<div role="alert" aria-live="assertive" aria-atomic="true" class="toast" data-bs-autohide="false">
<div class="toast-header">
<img src="..." class="rounded me-2" alt="...">
<strong class="me-auto">Bootstrap</strong>
<small>11 mins ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Hello, world! This is a toast message.
</div>
</div>
Mugihe muburyo bwa tekiniki birashoboka kongeramo ibitekerezo byibanze / bigenzurwa (nka buto yinyongera cyangwa amahuza) muri toast yawe, ugomba kwirinda kubikora kubwimodoka. Nubwo waha toast umwanya muremure , delay
clavier hamwe nabafasha gukoresha ikoranabuhanga birashobora kugorana kugera kuri toast mugihe cyo gufata ingamba (kubera ko toast itakira intumbero iyo yerekanwe). Niba ugomba rwose kugira ubundi bugenzuzi, turasaba gukoresha toast hamwe autohide: false
.
Sass
Ibihinduka
$toast-max-width: 350px;
$toast-padding-x: .75rem;
$toast-padding-y: .5rem;
$toast-font-size: .875rem;
$toast-color: null;
$toast-background-color: rgba($white, .85);
$toast-border-width: 1px;
$toast-border-color: rgba(0, 0, 0, .1);
$toast-border-radius: $border-radius;
$toast-box-shadow: $box-shadow;
$toast-spacing: $container-padding-x;
$toast-header-color: $gray-600;
$toast-header-background-color: rgba($white, .85);
$toast-header-border-color: rgba(0, 0, 0, .05);
Ikoreshwa
Gutangiza toast ukoresheje JavaScript:
var toastElList = [].slice.call(document.querySelectorAll('.toast'))
var toastList = toastElList.map(function (toastEl) {
return new bootstrap.Toast(toastEl, option)
})
Amahitamo
Amahitamo arashobora kunyuzwa kumurongo wamakuru cyangwa JavaScript. Kubiranga Ibyatanzwe, Ongeraho Ihitamo Izina Kuri data-bs-
, Nka Muri data-bs-animation=""
.
Izina | Andika | Mburabuzi | Ibisobanuro |
---|---|---|---|
animation |
boolean | true |
Koresha CSS igenda ihinduka kuri toast |
autohide |
boolean | true |
Hisha imodoka |
delay |
umubare | 5000 |
Gutinda guhisha toast (ms) |
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
Kugaragaza toast yikintu. Garuka kumuhamagaye mbere yuko toast yerekanwe mubyukuri (nukuvuga mbere yuko shown.bs.toast
ibyabaye biba). Ugomba guhamagara intoki ubu buryo, ahubgo toast yawe ntizerekana.
toast.show()
kwihisha
Hisha toast yikintu. Garuka kumuhamagaye mbere yuko toast ihishwa mubyukuri (nukuvuga mbere yuko hidden.bs.toast
ibyabaye biba). Ugomba guhamagara intoki ubu buryo niba autohide
wabikoze false
.
toast.hide()
guta
Hisha toast yikintu. Toast yawe izaguma kuri DOM ariko ntizongera kwerekana.
toast.dispose()
Kubona
Uburyo buhagaze butuma ubona urugero rwa scrollspy ifitanye isano na DOM element
var myToastEl = document.getElementById('myToastEl')
var myToast = bootstrap.Toast.getInstance(myToastEl) // Returns a Bootstrap toast instance
GetOrCreateInstance
Uburyo buhamye butuma ubona urugero rwa scrollspy rujyanye nibintu bya DOM, cyangwa gukora bundi bushya mugihe bitatangijwe
var myToastEl = document.getElementById('myToastEl')
var myToast = bootstrap.Toast.getOrCreateInstance(myToastEl) // Returns a Bootstrap toast instance
Ibyabaye
Ubwoko bwibyabaye | Ibisobanuro |
---|---|
show.bs.toast |
Ibirori birasa ako kanya mugihe show urugero rwitwa. |
shown.bs.toast |
Ibi birori birukanwa mugihe toast yakozwe kubakoresha. |
hide.bs.toast |
Ibi birori birahita bisohoka mugihe uburyo hide bwurugero bwahamagawe. |
hidden.bs.toast |
Ibirori birukanwa mugihe toast yarangije guhishwa uyikoresha. |
var myToastEl = document.getElementById('myToast')
myToastEl.addEventListener('hidden.bs.toast', function () {
// do something...
})