Bootstrap 5: Toasts


فهرست مطالب

    نمایش فهرست مطالب

ﺖﺴﺗ ﻥﺎﻧ

.(ﻩﺮﯿﻏ ﻭ ﺪﻨﮐ ﯽﻣ ﻝﺎﺳﺭﺍ ﺍﺭ ﯽﻣﺮﻓ ،ﺪﻨﮐ ﯽﻣ ﮏﯿﻠﮐ ﻪﻤﮐﺩ ﯼﻭﺭ ﺮﺑﺭﺎﮐ ﻪﮐ ﯽﻧﺎﻣﺯ ﯽﻨﻌﯾ) ﺩﻮﺷ ﯽ

Toast Header 5 mins ago

Some text inside the toast body


ﻢﯿﻨﮐ ﺖﺳﺭﺩ ﺖﺴﺗ ﻥﺎﻧ ﮏﯾ ﻪﻧﻮﮕﭼ

.ﺖﺳﺍ ﻥﺁ ﻞﺧﺍﺩ .toast-body code .ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﮏﯾ ﻭ

ﻪﺟﻮﺗ: ﯽﻣ ﺮﮔﺍ .ﺪﻨﺘﺴﻫ ﻥﺎﻬﻨﭘ ﺽﺮﻓ ﺶﯿﭘ ﺭﻮﻃ ﻪﺑ ﺎﻫ ﺖﺴﺗ ﻥﺎﻧﺱﻼﮐ ﺯ

<div class="toast show">
  <div class="toast-header">
    Toast Header
    <button type="button" class="btn-close" data-bs-dismiss="toast"></button>
  </div>
  <div class="toast-body">
    Some text inside the toast body
  </div>
</div>

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h3>Toast Example</h3>
  <p>A toast is like an alert box that is only shown for a couple of seconds when something happens (i.e. when a user clicks on a button, submits a form, etc.).</p>
  <p>In this example, we use the .show class to always show the toast by default. You can close it by clicking on the close (x) icon inside the toast header.</p>
  
  <div class="toast show">
    <div class="toast-header">
      <strong class="me-auto">Toast Header</strong>
      <button type="button" class="btn-close" data-bs-dismiss="toast"></button>
    </div>
    <div class="toast-body">
      <p>Some text inside the toast body</p>
    </div>
  </div>
</div>

</body>
</html>

ﺪﯿﻨﮐ ﺯﺎﺑ ﺍﺭ ﺖﺴﺗ ﻥﺎﻧ ﮏﯾ

.ﺪﯿﻨﮐ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ toast() ﺵﻭﺭ ﻭ ﺪﯿﻨﮐ ﺏﺎﺨﺘﻧﺍ ﺍ

:ﺪﻫﺩﯽﻣ ﻥﺎﺸﻧ ﺪﻨﺳ ﺭﺩ ﺍﺭ «ﺎﻫﺖﺴﺗ ﻥﺎﻧ» ﻪﻤﻫ ﺮﯾﺯ ﺪﮐ ،ﺪﯿﻨﮐﯽﻣ ﮏﯿﻠﮐ ﻪﻤﮐﺩ

ﻝﺎﺜﻣ

<script>
document.getElementById("toastbtn").onclick = function() {
  var toastElList = [].slice.call(document.querySelectorAll('.toast'))
  var toastList = toastElList.map(function(toastEl) {
    return new bootstrap.Toast(toastEl)
  })
  toastList.forEach(toast => toast.show())
}
</script>

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h3>Toast Example</h3>
  <p>In this example, we use a button to show the toast message.</p>

  <button type="button" class="btn btn-primary" id="toastbtn">Show Toast</button>
  
  <div class="toast">
    <div class="toast-header">
      <strong class="me-auto">Toast Header</strong>
      <button type="button" class="btn-close" data-bs-dismiss="toast"></button>
    </div>
    <div class="toast-body">
      <p>Some text inside the toast body</p>
    </div>
  </div>
</div>

<script>
document.getElementById("toastbtn").onclick = function() {
  var toastElList = [].slice.call(document.querySelectorAll('.toast'))
  var toastList = toastElList.map(function(toastEl) {
    return new bootstrap.Toast(toastEl)
  })
  toastList.forEach(toast => toast.show()) 
}
</script>

</body>
</html>