ټاسټونه
خپلو لیدونکو ته خبرتیاوې د ټوسټ ، لږ وزن لرونکي او په اسانۍ سره د تنظیم وړ خبرتیا پیغام سره فشار ورکړئ.
ټوسټونه لږ وزن لرونکي خبرتیاوې دي چې د پش خبرتیاو نقل کولو لپاره ډیزاین شوي چې د ګرځنده او ډیسټاپ عملیاتي سیسټمونو لخوا مشهور شوي. دوی د فلیکس بکس سره جوړ شوي، نو دوی د ترتیب او موقعیت لپاره اسانه دي.
کتنه
د ټوسټ پلگ ان کارولو پرمهال د پوهیدو لپاره شیان:
- که تاسو زموږ جاوا سکریپټ د سرچینې څخه جوړ کړئ، دا اړتیا لري
util.js
. - ټاسټونه د فعالیت دلایلو لپاره غوره شوي ، نو تاسو باید دوی پخپله پیل کړئ .
- ټاسټونه به په اوتومات ډول پټ شي که تاسو مشخص نه کړئ
autohide: false
.
مثالونه
اساسی
د تمدید وړ او وړاندوینې وړ ټیسټ هڅولو لپاره ، موږ سرلیک او بدن وړاندیز کوو. د ټوسټ سرلیکونه کاروي display: flex
، زموږ د حاشیې او فلیکس بکس اسانتیاو څخه مننه د مینځپانګې اسانه تنظیم کولو ته اجازه ورکوي.
ټوسټونه هغومره انعطاف منونکي دي څومره چې تاسو ورته اړتیا لرئ او خورا لږ اړین مارک اپ لري. لږترلږه، موږ یو واحد عنصر ته اړتیا لرو چې ستاسو "ټوسټ شوي" مینځپانګې ولري او په کلکه د ګوښه کولو تڼۍ وهڅوو.
شفاف
ټوسټونه هم یو څه شفاف دي، نو دوی په هر هغه څه سره مخلوط کوي چې ممکن یې ښکاره شي. د هغو براوزرونو لپاره چې د backdrop-filter
CSS ملکیت ملاتړ کوي، موږ به هڅه وکړو چې عناصر د ټوسټ لاندې روښانه کړو.
سټکینګ
کله چې تاسو ډیری ټوسټونه لرئ، موږ په عمودي ډول د لوستلو وړ اندازې سره د دوی ذخیره کولو لپاره ډیفالټ کوو.
ځای پرځای کول
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you’re only ever going to show one toast at a time, put the positioning styles right on the .toast
.
For systems that generate more notifications, consider using a wrapping element so they can easily stack.
You can also get fancy with flexbox utilities to align toasts horizontally and/or vertically.
Accessibility
Toasts are intended to be small interruptions to your visitors or users, so to help those with screen readers and similar assistive technologies, you should wrap your toasts in an aria-live
region. Changes to live regions (such as injecting/updating a toast component) are automatically announced by screen readers without needing to move the user’s focus or otherwise interrupt the user. Additionally, include aria-atomic="true"
to ensure that the entire toast is always announced as a single (atomic) unit, rather than announcing what was changed (which could lead to problems if you only update part of the toast’s content, or if displaying the same toast content at a later point in time). If the information needed is important for the process, e.g. for a list of errors in a form, then use the alert component instead of toast.
Note that the live region needs to be present in the markup before the toast is generated or updated. If you dynamically generate both at the same time and inject them into the page, they will generally not be announced by assistive technologies.
You also need to adapt the role
and aria-live
level depending on the content. If it’s an important message like an error, use role="alert" aria-live="assertive"
, otherwise use role="status" aria-live="polite"
attributes.
As the content you’re displaying changes, be sure to update the delay
timeout to ensure people have enough time to read the toast.
When using autohide: false
, you must add a close button to allow users to dismiss the toast.
JavaScript behavior
Usage
Initialize toasts via JavaScript:
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-animation=""
.
Name | Type | Default | Description |
---|---|---|---|
animation | boolean | true | Apply a CSS fade transition to the toast |
autohide | boolean | true | Auto hide the toast |
delay | number | 500 |
Delay hiding the toast (ms) |
Methods
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
$().toast(options)
Attaches a toast handler to an element collection.
.toast('show')
Reveals an element’s toast. Returns to the caller before the toast has actually been shown (i.e. before the shown.bs.toast
event occurs). You have to manually call this method, instead your toast won’t show.
.toast('hide')
Hides an element’s toast. Returns to the caller before the toast has actually been hidden (i.e. before the hidden.bs.toast
event occurs). You have to manually call this method if you made autohide
to false
.
.toast('dispose')
Hides an element’s toast. Your toast will remain on the DOM but won’t show anymore.
Events
Event Type | Description |
---|---|
show.bs.toast | This event fires immediately when the show instance method is called. |
shown.bs.toast | This event is fired when the toast has been made visible to the user. |
hide.bs.toast | دا پیښه سمدلاسه له مینځه وړل کیږي کله چې د hide مثال میتود ویل کیږي. |
hidden.bs.toast | دا پیښه له مینځه وړل کیږي کله چې ټوسټ د کارونکي څخه پټ شوی وي. |