Esasy mazmuna geçiň Docs nawigasiýasyna geçiň
in English

Tostlar

Tost, ýeňil we aňsat düzülip bilinýän duýduryş habary bilen gelýänleriňize bildirişleri basyň.

Tostlar, ykjam we iş stoly operasiýa ulgamlary tarapyndan meşhur bolan itek habarnamalaryny meňzeş etmek üçin döredilen ýeňil bildirişlerdir. Flexbox bilen gurlan, şonuň üçin deňleşdirmek we ýerleşdirmek aňsat.

Gysgaça syn

Tost plaginini ulananyňyzda bilmeli zatlar:

  • Tostlar öndürijilik sebäplerine görä saýlanýar, şonuň üçin olary özüňiz başlamaly .
  • Tostlar görkezmeseňiz awtomatiki usulda gizlener autohide: false.
Bu komponentiň animasiýa täsiri prefers-reduced-motionmedia talaplaryna baglydyr. Elýeterlilik resminamalarymyzyň azaldylan hereket bölümine serediň .

Mysallar

Esasy

Giňeldilip bilinýän we öňünden aýdyp boljak tostlary höweslendirmek üçin sözbaşy we göwre maslahat berýäris. Tost sözbaşylary display: flex, margin we flexbox kömekçi enjamlarymyzyň kömegi bilen mazmuny aňsat deňleşdirmäge mümkinçilik berýär.

Tostlar zerur bolşy ýaly çeýe we zerur bellik az. Iň bolmanda, “tostlanan” mazmunyňyzy saklamak we işden çykarmak düwmesini güýçli höweslendirmek üçin ýekeje element talap edýäris.

<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>
Ozal ýazgylarymyz .hidetosty doly gizlemek üçin ( display:nonediňe däl-de, eýsem opacity:0) synpy dinamiki taýdan goşýardy. Indi bu zerur däl. Şeýle-de bolsa, yza gabat gelmek üçin skriptimiz indiki esasy wersiýa çenli synpy üýtgetmäge dowam eder (munuň üçin amaly zerurlyk bolmasa-da).

Göni mysal

Dymmaklyk bilen gizlenen tosty görkezmek üçin aşakdaky düwmä basyň.

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

Göni tost görkezişimizi açmak üçin aşakdaky JavaScript ulanýarys:

var toastTrigger = document.getElementById('liveToastBtn')
var toastLiveExample = document.getElementById('liveToast')
if (toastTrigger) {
  toastTrigger.addEventListener('click', function () {
    var toast = new bootstrap.Toast(toastLiveExample)

    toast.show()
  })
}

Düşünjeli

Tostlar, aşaky zatlar bilen garyşmak üçin birneme düşnüklidir.

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

Ackygyndy

Tostlary dikligine birneme aralyk goşjak tost gabyna salyp, toplap bilersiňiz.

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

Omörite mazmun

Bölek bölekleri aýyrmak, kommunal hyzmatlar bilen üýtgetmek ýa-da öz belligiňizi goşmak bilen tostlaryňyzy sazlaň. Bu ýerde deslapky aýyryp, Bootstrap nyşanlaryndan.toast-header ýörite gizlin nyşany goşup we tertibi sazlamak üçin käbir flexbox kömekçi enjamlaryny ulanyp has ýönekeý tost döretdik .

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

.A-da bolmasa, tostlara goşmaça dolandyryş we komponentler goşup bilersiňiz.

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

Reňk shemalary

Aboveokardaky mysaldan ugur alyp, reňkimiz we fon hyzmatlarymyz bilen dürli tost reňk shemalaryny döredip bilersiňiz. Bu ýerde goşduk .bg-primarywe goşduk .text-white, .toastsoň bolsa .btn-close-whiteýakyn düwmämize goşduk. Gysga gyrasy üçin, adaty araçägi aýyrýarys .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>

Acementerleşiş

Gerekli CSS bilen tostlary ýerleşdiriň. Rightokarky sag ýokarky ýokarky ýaly köplenç habarnamalar üçin ulanylýar. Bir gezekde diňe bir tost görkezjek bolsaňyz, ýerleşiş stillerini sag tarapda goýuň .toast.

Bootstrap 11 minut öň
Salam, dünýä! Bu tost habary.
<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>

Has köp habarnamalary döredýän ulgamlar üçin, aňsatlyk bilen ýapyşyp bilmekleri üçin, gaplama elementini ulanmagy göz öňünde tutuň.

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

Şeýle hem, tostlary keseligine we / ýa-da dikligine deňlemek üçin flexbox kömekçi enjamlary bilen gyzyklanyp bilersiňiz.

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

Elýeterlilik

Tostlar, gelýänleriňize ýa-da ulanyjylaryňyza ownuk bökdençlikler üçin niýetlenendir, şonuň üçin ekran okyjylary we şuňa meňzeş kömekçi tehnologiýalary bolanlara kömek etmek üçin tostlaryňyzy bir aria-livesebite ýapmaly . Janly sebitlerdäki üýtgeşmeler (meselem, tost komponentine sanjym / täzelenmek ýaly) ulanyjynyň ünsüni üýtgetmek ýa-da ulanyjyny başga birine päsgel bermek zerurlygy bolmazdan, awtomatiki usulda ekran okyjylary tarapyndan yglan edilýär. Mundan başga- da, aria-atomic="true"üýtgedilen zady yglan etmek däl-de, tostuň mazmunynyň diňe bir bölegini täzeleseňiz ýa-da şol bir tost mazmunyny görkezseňiz, tutuş tostuň hemişe bir (atom) birligi hökmünde yglan edilmegini üpjün ediň. soňraky nokadynda). Gerekli maglumatlar amal üçin möhüm bolsa, mysal üçin bir görnüşdäki ýalňyşlyklaryň sanawy üçin, duýduryş komponentini ulanyňtost ýerine.

Tost döredilmezden ýa-da täzelenmezden ozal janly sebitiň bellikde bolmalydygyny unutmaň . Şol bir wagtyň özünde ikisini hem dinamiki görnüşde döredip, sahypa salsaňyz, köplenç kömekçi tehnologiýalar tarapyndan yglan edilmez.

Şeýle hem mazmuna baglylykda derejäni rolewe derejäni uýgunlaşdyrmaly . aria-liveErroralňyşlyk ýaly möhüm habar bolsa, ulanyň role="alert" aria-live="assertive", bolmasa role="status" aria-live="polite"atributlary ulanyň.

Görkezýän mazmunyňyzyň üýtgemegi bilen, ulanyjylaryň tosty okamak üçin ýeterlik wagty bolar ýaly , delaygutarýan wagty täzeläň.

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

Ulanylanda autohide: false, ulanyjylara tostdan ýüz öwürmek üçin ýakyn düwme goşmaly.

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

Tehniki taýdan tostuňyza ünsi jemläp boljak / hereket edip bolýan dolandyryşlary (goşmaça düwmeler ýa-da baglanyşyklar) goşmak mümkin bolsa-da, tostlary awtomatiki gizlemek üçin muny etmeli däl. delayTosta uzak wagt berseňizem , klawiatura we kömekçi tehnologiýa ulanyjylary herekete geçmek üçin tosta wagtynda ýetmegi kynlaşdyryp bilerler (sebäbi tostlar görkezilende ünsi almaýar). Mundan başga-da gözegçilik etmeli bolsaňyz, tost ulanmagy maslahat berýäris autohide: false.

Sass

Üýtgeýjiler

$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($black, .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($black, .05);

Ulanylyşy

JavaScript arkaly tostlary başlaň:

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

Triggerler

Aşakda görkezilişi ýaly tostuň içindäki düwmedäkidata atribut bilen işden aýrylyp bilner :

<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>

ýa-da aşakda görkezilişi ýaly tostuň daşyndaky düwmede :data-bs-target

<button type="button" class="btn-close" data-bs-dismiss="toast" data-bs-target="#my-toast" aria-label="Close"></button>

Görnüş

Opsiýalar maglumat atributlary ýa-da JavaScript arkaly geçirilip bilner. Maglumat atributlary üçin, opsiýanyň adyny data-bs-bolşy ýaly goşuň data-bs-animation="".

Ady Görnüşi Bellenen Düşündiriş
animation boolean true Tosta CSS solgun geçişini ulanyň
autohide boolean true Tosty awtomatik gizläň
delay sany 5000 Tosty gizlemek (ms)

Usullar

Asynkron usullar we geçişler

APIhli API usullary asynkron bolup, geçişe başlaýar . Geçiş başlan badyna, ýöne gutarmanka jaň edijä gaýdyp gelýärler . Mundan başga-da, geçiş komponentine çagyryş usuly hasaba alynmaz .

Has giňişleýin maglumat üçin JavaScript resminamalarymyza serediň .

görkezmek

Bir elementiň tostyny ​​açýar. Tost görkezilmänkä (ýagny shown.bs.toastwaka ýüze çykmazdan ozal) jaň edýän adama gaýdyp gelýär. Bu usuly el bilen çagyrmaly, ýerine tostyňyz görkezilmez.

toast.show()

gizle

Bir elementiň tostyny ​​gizleýär. Tost hakykatdanam gizlenmänkä (ýagny waka ýüze çykmazdan ozal) jaň edýän adama gaýdyp gelýär . hidden.bs.toastBu usuly el bilen autohideçagyrmaly false.

toast.hide()

taşlaň

Bir elementiň tostyny ​​gizleýär. Tostyňyz DOM-da galar, ýöne indi görkezmez.

toast.dispose()

GetInstance

DOM elementi bilen baglanyşykly tost mysalyny almaga mümkinçilik berýän statiki usul

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

getOrCreateInstance

DOM elementi bilen baglanyşykly tost mysalyny almaga ýa-da başlamadyk ýagdaýynda täzesini döretmäge mümkinçilik berýän statiki usul.

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

Wakalar

Çäräniň görnüşi Düşündiriş
show.bs.toast showBu waka mysal usuly çagyrylanda derrew ýanýar .
shown.bs.toast Bu waka tost ulanyja görünen mahaly atylýar.
hide.bs.toast Bu waka hidemysal usuly çagyrylanda derrew atylýar.
hidden.bs.toast Bu waka tost ulanyjydan gizlenenden soň atylýar.
var myToastEl = document.getElementById('myToast')
myToastEl.addEventListener('hidden.bs.toast', function () {
  // do something...
})