Pitani kuzinthu zazikulu Pitani kumayendedwe adocs

Kankhani zidziwitso kwa alendo anu ndi toast, uthenga wopepuka komanso wachenjezo wosavuta kusintha.

Ma toast ndi zidziwitso zopepuka zopangidwira kutsanzira zidziwitso zokankhira zomwe zatchuka ndi makina ogwiritsira ntchito mafoni ndi apakompyuta. Amapangidwa ndi flexbox, kotero ndi osavuta kugwirizanitsa ndi malo.

Mwachidule

Zomwe muyenera kudziwa mukamagwiritsa ntchito pulogalamu ya toast:

  • Ma toast amasankha kulowa chifukwa cha magwiridwe antchito, chifukwa chake muyenera kuwayambitsa nokha .
  • Ma toast amabisala okha ngati simunatchule autohide: false.
Kanema wa gawoli amadalira prefers-reduced-motionfunso la media. Onani gawo lochepetsedwa la zolemba zathu zofikira .

Zitsanzo

Basic

Pofuna kulimbikitsa ma toast owonjezera komanso odziwikiratu, timalimbikitsa mutu ndi thupi. Mitu ya toast imagwiritsa ntchito display: flex, kulola kusanja kosavuta kwa zomwe zili m'mphepete mwathu ndi zida za flexbox.

Ma toast amasinthasintha momwe mungafunire ndipo amakhala ndi zolembera zochepa. Pang'ono ndi pang'ono, tikufuna chinthu chimodzi kuti chikhale ndi "chowotcha" ndikulimbikitsani kuti muchotse.

<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>

Khalani ndi moyo

Dinani batani ili m'munsimu kuti muwonetse chotupitsa (chomwe chili ndi zida zathu kumunsi kumanja) chomwe chabisika mwachisawawa ndi .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>

Zowoneka bwino

Ma toast amawonekera pang'ono kuti agwirizane ndi zomwe zili pansi pake.

<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>

Stacking

Mukhoza kuyika toasts powakulunga mu chidebe chofufumitsa, chomwe chidzawonjezera kusiyana.

<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>

Zomwe zili mwamakonda

Sinthani ma toast anu pochotsa zing'onozing'ono, kuzisintha ndi zofunikira , kapena powonjezera zolemba zanu. Apa tapanga chofufumitsa chosavuta pochotsa chokhazikika .toast-header, kuwonjezera chizindikiro chobisala chobisika kuchokera ku Zithunzi za Bootstrap , ndi kugwiritsa ntchito zida za flexbox kuti musinthe masanjidwewo.

<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>

Kapenanso, mutha kuwonjezera maulamuliro owonjezera ndi zigawo ku 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>

Mitundu yamitundu

Pogwiritsa ntchito chitsanzo chomwe chili pamwambapa, mutha kupanga mitundu yosiyanasiyana yamitundu ya toast ndi utoto wathu ndi zida zakumbuyo . Apa tawonjezera .bg-primaryndi .text-whiteku .toast, ndikuwonjezera .btn-close-whiteku batani lathu lotseka. Kwa m'mphepete mwake, timachotsa malire okhazikika ndi .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>

Kuyika

Ikani toast ndi CSS yokhazikika momwe mukufunira. Chapamwamba kumanja nthawi zambiri amagwiritsidwa ntchito pazidziwitso, monganso chapakati chapakati. Ngati mungowonetsa chotupitsa chimodzi panthawi, ikani masitaelo oyika pa .toast.

Bootstrap Mphindi 11 zapitazo
Moni Dziko Lapansi! Uwu ndi uthenga wa 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>

Pamakina omwe amapanga zidziwitso zambiri, lingalirani kugwiritsa ntchito chinthu chokulungidwa kuti athe kusanjika mosavuta.

<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>

Muthanso kukhala osangalatsa ndi zida za flexbox kuti mugwirizane ndi toast molunjika komanso/kapena molunjika.

<!-- 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>

Kufikika

Ma toast amapangidwa kuti akhale zosokoneza pang'ono kwa alendo anu kapena ogwiritsa ntchito, kotero kuti muthandize omwe ali ndi zowerengera zowonera ndi matekinoloje othandizira ofanana, muyenera kukulunga ma toast anu aria-livem'dera . Zosintha m'zigawo zomwe zikuchitika (monga kubayira/kukonzanso kagawo kakang'ono ka toast) zimalengezedwa ndi owerenga zenera popanda kufunikira kusuntha malingaliro a wogwiritsa ntchito kapena kusokoneza wogwiritsa ntchito. Kuphatikiza apo, phatikizani aria-atomic="true"kuwonetsetsa kuti toast yonse imalengezedwa nthawi zonse ngati gawo limodzi (atomiki), m'malo mongolengeza zomwe zasinthidwa (zomwe zingayambitse mavuto ngati mungosintha gawo lazofufumitsa, kapena ngati mukuwonetsa zomwe zasinthidwazo. m'malo mwake). Ngati zomwe zikufunika ndi zofunika pa ndondomekoyi, mwachitsanzo pa mndandanda wa zolakwika mu fomu, ndiye gwiritsani ntchito chigawo chochenjeza.m'malo mwa toast.

Zindikirani kuti dera lomwe lilipo likuyenera kukhalapo polembapo toast isanapangidwe kapena kusinthidwa . Ngati mupanga zonse ziwiri nthawi imodzi ndikuzilowetsa patsamba, sizingalengezedwe ndi matekinoloje othandizira.

Muyeneranso kusintha rolendi aria-livemlingo malinga ndi zili. Ngati ndi uthenga wofunikira ngati cholakwika, gwiritsani ntchito role="alert" aria-live="assertive", apo ayi gwiritsani ntchito mawonekedwe role="status" aria-live="polite".

Pamene zomwe mukuwonetsa zikusintha, onetsetsani kuti mwasintha delaynthawi yomaliza kuti ogwiritsa ntchito azikhala ndi nthawi yokwanira yowerengera 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>

Mukamagwiritsa ntchito autohide: false, muyenera kuwonjezera batani lotseka kuti mulole ogwiritsa ntchito kusiya 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>

Ngakhale mwaukadaulo ndizotheka kuwonjezera zowongolera zowoneka bwino / zotheka (monga mabatani owonjezera kapena maulalo) mu toast yanu, muyenera kupewa kuchita izi pobisala toast. Ngakhale mutapatsa chofufumitsa nthawi yayitali delay, ogwiritsa ntchito kiyibodi ndi ukadaulo wothandizira angavutike kuti afikire toast munthawi yake kuti achitepo kanthu (popeza ma toast samayang'ana kwambiri akawonetsedwa). Ngati mukuyenera kukhala ndi zowongolera zina, timalimbikitsa kugwiritsa ntchito toast yokhala ndi autohide: false.

Sass

Zosintha

$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);

Kugwiritsa ntchito

Yambitsani toast kudzera pa JavaScript:

var toastElList = [].slice.call(document.querySelectorAll('.toast'))
var toastList = toastElList.map(function (toastEl) {
  return new bootstrap.Toast(toastEl, option)
})

Zosankha

Zosankha zitha kuperekedwa kudzera pa data kapena JavaScript. Pamawonekedwe a data, yonjezerani dzina lachisankho ku data-bs-, monga mu data-bs-animation="".

Dzina Mtundu Zosasintha Kufotokozera
animation boolean true Ikani kusintha kwa CSS kufila ku toast
autohide boolean true Bisani tositi yokha
delay nambala 5000 Kuchedwa kubisa tositi (ms)

Njira

Asynchronous njira ndi kusintha

Njira zonse za API ndizosasinthika ndipo zimayamba kusintha . Amabwerera kwa woyimbayo atangoyamba kusintha koma asanathe . Kuonjezera apo, kuyitana kwa njira pa gawo losintha kudzanyalanyazidwa .

Onani zolemba zathu za JavaScript kuti mudziwe zambiri .

chiwonetsero

Imawulula toast ya element. Imabwereranso kwa woyimba foniyo isanasonyezedwe (ie zisanachitike shown.bs.toast). Muyenera kuyimbira njira iyi pamanja, m'malo mwake chotupitsa chanu sichidzawonekera.

toast.show()

kubisa

Imabisa tositi ya chinthu. Imabwereranso kwa woyimbirayo tisanabisike (mwachitsanzo, hidden.bs.toastchochitikacho chisanachitike). Muyenera kuyimbira pamanja njira iyi ngati autohidemunapanga false.

toast.hide()

kutaya

Imabisa tositi ya chinthu. Chotupitsa chanu chidzatsalira pa DOM koma sichidzawonekeranso.

toast.dispose()

getInstance

Njira yosasunthika yomwe imakupatsani mwayi woti mutenge scrollspy chitsanzo cholumikizidwa ndi chinthu cha DOM

var myToastEl = document.getElementById('myToastEl')
var myToast = bootstrap.Toast.getInstance(myToastEl) // Returns a Bootstrap toast instance

GetOrCreateInstance

Njira yosasunthika yomwe imakulolani kuti mutenge chitsanzo cha scrollspy cholumikizidwa ndi chinthu cha DOM, kapena pangani china chatsopano ngati sichinayambike.

var myToastEl = document.getElementById('myToastEl')
var myToast = bootstrap.Toast.getOrCreateInstance(myToastEl) // Returns a Bootstrap toast instance

Zochitika

Mtundu wa chochitika Kufotokozera
show.bs.toast Chochitika ichi chimayaka nthawi yomweyo shownjira yachitsanzo itayitanidwa.
shown.bs.toast Chochitika ichi chimathamangitsidwa pamene chofufumitsa chawonetsedwa kwa wogwiritsa ntchito.
hide.bs.toast Chochitika ichi chimachotsedwa nthawi yomweyo pamene hidenjira yachitsanzo yayitanidwa.
hidden.bs.toast Chochitikachi chimathamangitsidwa pamene tositi yatha kubisidwa kwa wogwiritsa ntchito.
var myToastEl = document.getElementById('myToast')
myToastEl.addEventListener('hidden.bs.toast', function () {
  // do something...
})