Toasts
Pana whakamohiotanga ki o manuhiri me te toast, he panui matohi ngawari me te ngawari te whakarite.
Ko nga Toasts he panui ngawari i hangaia hei whakatauira i nga panui pana kua rongonuihia e nga punaha whakahaere pūkoro me te papamahi. He mea hanga ki te flexbox, no reira he ngawari ki te tiro me te tuunga.
Tirohanga
Nga mea hei mohio ina whakamahi ana i te mono toast:
- Ka uru mai nga toasts mo nga take mahi, no reira me arawhiti koe maau ano .
- Ka huna aunoa te toasts ki te kore koe e whakapūtā
autohide: false
.
prefers-reduced-motion
uiui pāpāho. Tirohia te
waahanga motini whakaheke o a maatau tuhinga whakaurunga .
Tauira
Taketake
Hei whakatenatena i nga toast ka taea te whakawhanui me te matapae, ka tūtohu matou he pane me te tinana. Ka whakamahia e nga pane toast display: flex
, he ngawari ki te whakatika i nga ihirangi ma te mihi ki nga taputapu tawhē me te pouaka flexbox.
He ngawari te toasts ki taau e hiahia ana, he iti noa nga tohu e hiahiatia ana. I te iti rawa, ka hiahia matou ki tetahi huānga hei whakauru i o ihirangi "tohe" me te akiaki i te paatene whakakore.
<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>
Ora
Patohia te paatene i raro nei hei whakaatu i te toast (kua tu me o maatau taputapu ki te kokonga matau o raro) kua hunahia e te taunoa me te .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>
Puatarangi
He paku marama te toasts ki te whakakotahi ki nga mea kei raro iho.
<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>
Tāpae
Ka taea e koe te tapae i nga toasts ma te takai ki roto i te ipu toast, ka taapiri poutū te mokowā.
<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>
Ihirangi ritenga
Whakaritehia o toasts ma te tango i nga waahanga-iti, te takawiri ki nga taputapu , ma te taapiri ranei i a koe ake tohu. I konei kua hangahia e matou he toast ngawari ake ma te tango i te taunoa .toast-header
, me te taapiri i tetahi tohu huna mai i nga Ata Bootstrap , me te whakamahi i etahi taputapu flexbox hei whakatika i te whakatakotoranga.
<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>
I tua atu, ka taea e koe te taapiri i etahi atu mana whakahaere me nga waahanga ki nga toasts.
<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>
Kaupapa tae
Ko te hanga i runga i te tauira o runga ake nei, ka taea e koe te hanga i nga momo tae toast me o maatau taputapu tae me te papamuri . I konei kua taapirihia e matou .bg-primary
me .text-white
te .toast
, katahi ka taapiri atu .btn-close-white
ki ta maatau paatene kati. Mo te tapa kirikiri, ka tangohia e matou te taitapa taunoa me te .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>
Whakanoho
Whakanohoia nga toasts me te CSS ritenga e hiahia ana koe. Ka whakamahia te taha matau o runga mo nga whakamohiotanga, pera i te waenganui o runga. Mena ka whakaatu noa koe i te toast kotahi i te wa kotahi, tuu tika nga momo tuunga ki runga i te .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>
Mo nga punaha ka nui ake nga whakamohiotanga, whakaarohia te whakamahi i tetahi huānga takai kia ngawari ai te tapae.
<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>
Ka taea hoki e koe te ahuareka ki nga taputapu flexbox ki te whakahāngai i te toast ki te whakapae me te poutū ranei.
<!-- 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>
Te urunga
Ko te tikanga o te toasts he aukati iti ki o manuhiri, ki nga kaiwhakamahi ranei, no reira hei awhina i te hunga whai panui mata me nga hangarau awhina rite, me takai e koe o toasts ki tetahi aria-live
rohe . Ko nga huringa ki nga rohe ora (penei i te werohia/whakahou i te waahanga toast) ka panui aunoa e nga kaipanui mata me te kore e nuku i te arotahi o te kaiwhakamahi, ki te kore ranei e haukotia te kaiwhakamahi. I tua atu, whakaurua aria-atomic="true"
ki te whakarite kia panuitia te katoa o te toast hei waeine kotahi (ngota), kaua ki te panui i nga mea i whakarereke (ka raru pea mena ka whakahou koe i tetahi waahanga o te ihirangi o te toast, mena ka whakaatu i nga ihirangi toast rite tonu. i tetahi wa i muri mai). Mena he mea nui nga korero e hiahiatia ana mo te tukanga, hei tauira mo te rarangi o nga hapa i roto i te ahua, ka whakamahi i te waahanga mataarahei utu mo te tunu.
Kia mahara ko te rohe ora me noho ki roto i te tohu i mua i te whakaputanga, te whakahou ranei i te toast. Mena ka hangai koe i nga mea e rua i te wa kotahi ka werohia ki roto i te wharangi, kaore e panuitia e nga hangarau awhina.
Me urutau ano koe i te role
me te aria-live
taumata i runga i te ihirangi. Mena he karere nui penei i te hapa, whakamahia role="alert" aria-live="assertive"
, ki te kore whakamahi role="status" aria-live="polite"
huanga.
I te mea ka huri nga korero e whakaatuhia ana e koe, me whakahōu i te delay
wa mutunga kia nui te taima a nga kaiwhakamahi ki te panui i te 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>
I te wa e whakamahi ana autohide: false
, me taapiri he paatene kati kia taea e nga kaiwhakamahi te whakakore i te 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>
Ahakoa te tikanga ka taea te taapiri i nga mana arotahi/whakamahia (penei i nga paatene taapiri, hononga hono ranei) i roto i to tunu tunu, me karo koe ki te mahi i tenei mo te toast huna aunoa. Ahakoa ka hoatu e koe he wa roa ki te toast delay
, ka uaua pea nga kaiwhakamahi papapātuhi me te hangarau awhina ki te toro atu ki te toast i te wa ki te mahi (i te mea karekau e aro te toasts ina whakaatuhia ana). Mena kei a koe etahi atu mana whakahaere, ka tūtohu matou ki te whakamahi i te toast me te autohide: false
.
Sass
Taurangi
$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);
Whakamahinga
Whakaokirihia nga toast ma te JavaScript:
var toastElList = [].slice.call(document.querySelectorAll('.toast'))
var toastList = toastElList.map(function (toastEl) {
return new bootstrap.Toast(toastEl, option)
})
Kōwhiringa
Ko nga whiringa ka taea te tuku ma nga huanga raraunga, JavaScript ranei. Mo nga huanga raraunga, apitihia te ingoa whiringa ki data-bs-
, penei i te data-bs-animation=""
.
Ingoa | Momo | Taunoa | Whakaahuatanga |
---|---|---|---|
animation |
boolean | true |
Hoatu he whakawhiti memeha CSS ki te toast |
autohide |
boolean | true |
Huna aunoa i te toast |
delay |
tau | 5000 |
Whakaroa te huna i te toast (ms) |
Nga tikanga
Nga tikanga tukutahi me nga whakawhitinga
Ko nga tikanga API katoa he tukutahi ka timata te whakawhiti . Ka hoki mai ano ki te kaikaranga ina timata te whakawhiti engari i mua i te mutunga . I tua atu, ka warewarehia te karanga tikanga mo tetahi waahanga whakawhiti .
whakaatu
He whakaatu i te toast a te huānga. Ka hoki ki te kaiwaea i mua i te whakaaturanga o te toast (arā i mua i te shown.bs.toast
puta o te takahanga). Me waea a ringa koe ki tenei tikanga, engari kare to tunu e whakaatu.
toast.show()
huna
Hunaia te toast a te huānga. Ka hoki ki te kaiwaea i mua i te hunanga o te toast (arā i mua i te hidden.bs.toast
puta o te takahanga). Me waea atu koe ki tenei tikanga mena ka mahia e autohide
koe false
.
toast.hide()
tuku
Hunaia te toast a te huānga. Ka noho tonu to tunutunu ki te DOM engari kare e whakaatu.
toast.dispose()
getInstance
Tikanga pateko e taea ai e koe te tiki i te tauira scrollspy e hono ana ki tetahi huānga DOM
var myToastEl = document.getElementById('myToastEl')
var myToast = bootstrap.Toast.getInstance(myToastEl) // Returns a Bootstrap toast instance
getOrCreateInstance
Tikanga pateko e taea ai e koe te tiki i te tauira scrollspy e hono ana ki tetahi huānga DOM, ki te hanga i tetahi mea hou mena kaore i arawhitia
var myToastEl = document.getElementById('myToastEl')
var myToast = bootstrap.Toast.getOrCreateInstance(myToastEl) // Returns a Bootstrap toast instance
Nga huihuinga
Momo takahanga | Whakaahuatanga |
---|---|
show.bs.toast |
Ka pupuhi tenei takahanga ina ka show karangahia te aratuka tauira. |
shown.bs.toast |
Ka pupuhihia tenei takahanga i te wa i kitea ai te toast ki te kaiwhakamahi. |
hide.bs.toast |
Ka puhia tonutia tenei takahanga ina hide kua karangahia te aratuka tauira. |
hidden.bs.toast |
Ka puhia tenei takahanga ina mutu te hunanga o te toast mai i te kaiwhakamahi. |
var myToastEl = document.getElementById('myToast')
myToastEl.addEventListener('hidden.bs.toast', function () {
// do something...
})