મુખ્ય સામગ્રી પર જાઓ ડૉક્સ નેવિગેશન પર જાઓ
in English

ટોસ્ટ્સ

તમારા મુલાકાતીઓને ટોસ્ટ, હળવા અને સરળતાથી કસ્ટમાઇઝ કરી શકાય તેવા ચેતવણી સંદેશ સાથે સૂચનાઓ મોકલો.

ટોસ્ટ એ હળવા વજનની સૂચનાઓ છે જે પુશ સૂચનાઓની નકલ કરવા માટે રચાયેલ છે જે મોબાઇલ અને ડેસ્કટોપ ઓપરેટિંગ સિસ્ટમ દ્વારા લોકપ્રિય કરવામાં આવી છે. તેઓ ફ્લેક્સબોક્સ સાથે બનેલ છે, જેથી તેઓ સંરેખિત અને સ્થિત કરવામાં સરળ હોય.

ઝાંખી

ટોસ્ટ પ્લગઇનનો ઉપયોગ કરતી વખતે જાણવા જેવી બાબતો:

  • ટોસ્ટ્સ કાર્યક્ષમતાના કારણોસર પસંદ કરવામાં આવે છે, તેથી તમારે તેને જાતે જ પ્રારંભ કરવું આવશ્યક છે .
  • જો તમે ઉલ્લેખિત ન કરો તો ટોસ્ટ્સ આપમેળે છુપાવશે autohide: false.
આ ઘટકની એનિમેશન અસર prefers-reduced-motionમીડિયા ક્વેરી પર આધારિત છે. અમારા ઍક્સેસિબિલિટી દસ્તાવેજીકરણનો ઘટાડો ગતિ વિભાગ જુઓ .

ઉદાહરણો

પાયાની

એક્સ્ટેન્સિબલ અને અનુમાનિત ટોસ્ટ્સને પ્રોત્સાહિત કરવા માટે, અમે હેડર અને બોડીની ભલામણ કરીએ છીએ. display: flexઅમારા માર્જિન અને ફ્લેક્સબોક્સ ઉપયોગિતાઓને આભારી સામગ્રીના સરળ સંરેખણની મંજૂરી આપતા, ટોસ્ટ હેડરોનો ઉપયોગ કરે છે.

ટોસ્ટ્સ તમને જરૂર હોય તેટલા લવચીક હોય છે અને તેમાં બહુ ઓછા જરૂરી માર્કઅપ હોય છે. ન્યૂનતમ, અમને તમારી "ટોસ્ટેડ" સામગ્રી શામેલ કરવા માટે અને બરતરફ બટનને મજબૂત રીતે પ્રોત્સાહિત કરવા માટે એક ઘટકની જરૂર છે.

<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>
અગાઉ, અમારી સ્ક્રિપ્ટો .hideટોસ્ટને સંપૂર્ણપણે છુપાવવા માટે ગતિશીલ રીતે વર્ગને ઉમેરતી હતી ( display:noneમાત્ર ની સાથે , સાથે નહીં opacity:0). હવે આની જરૂર નથી. જો કે, પાછળની સુસંગતતા માટે, અમારી સ્ક્રિપ્ટ આગામી મુખ્ય સંસ્કરણ સુધી વર્ગને ટૉગલ કરવાનું ચાલુ રાખશે (તેની કોઈ વ્યવહારિક જરૂરિયાત ન હોવા છતાં).

જીવંત ઉદાહરણ

ડિફૉલ્ટ રૂપે છુપાવેલ ટોસ્ટ (નીચલા જમણા ખૂણામાં અમારી ઉપયોગિતાઓ સાથે સ્થિત) બતાવવા માટે નીચેના બટનને ક્લિક કરો.

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

અમે અમારા લાઇવ ટોસ્ટ ડેમોને ટ્રિગર કરવા માટે નીચેની JavaScript નો ઉપયોગ કરીએ છીએ:

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

    toast.show()
  })
}

અર્ધપારદર્શક

ટોસ્ટ તેમની નીચે જે છે તેની સાથે મિશ્રણ કરવા માટે સહેજ અર્ધપારદર્શક હોય છે.

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

સ્ટેકીંગ

તમે ટોસ્ટને ટોસ્ટ કન્ટેનરમાં લપેટીને સ્ટેક કરી શકો છો, જે ઊભી રીતે થોડો અંતર ઉમેરશે.

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

કસ્ટમ સામગ્રી

પેટા ઘટકોને દૂર કરીને, તેમને ઉપયોગિતાઓ સાથે ટ્વિક કરીને અથવા તમારું પોતાનું માર્કઅપ ઉમેરીને તમારા ટોસ્ટને કસ્ટમાઇઝ કરો. અહીં અમે ડિફોલ્ટને દૂર કરીને , બુટસ્ટ્રેપ.toast-header આઇકોન્સમાંથી કસ્ટમ હાઇડ આઇકોન ઉમેરીને અને લેઆઉટને સમાયોજિત કરવા માટે કેટલીક ફ્લેક્સબોક્સ ઉપયોગિતાઓનો ઉપયોગ કરીને સરળ ટોસ્ટ બનાવ્યું છે.

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

વૈકલ્પિક રીતે, તમે ટોસ્ટમાં વધારાના નિયંત્રણો અને ઘટકો પણ ઉમેરી શકો છો.

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

રંગ યોજનાઓ

ઉપરના ઉદાહરણના આધારે, તમે અમારી રંગ અને પૃષ્ઠભૂમિ ઉપયોગિતાઓ સાથે વિવિધ ટોસ્ટ રંગ યોજનાઓ બનાવી શકો છો . અહી અમે , અને પછી .bg-primaryઅમારા .text-whiteબંધ બટનમાં ઉમેર્યું છે. ચપળ ધાર માટે, અમે ની સાથે ડિફોલ્ટ સરહદ દૂર કરીએ છીએ ..toast.btn-close-white.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>

પ્લેસમેન્ટ

તમને જરૂર મુજબ કસ્ટમ CSS સાથે ટોસ્ટ્સ મૂકો. ટોચની જમણી બાજુનો ઉપયોગ ઘણીવાર સૂચનાઓ માટે થાય છે, જેમ કે ટોચની મધ્યમાં છે. જો તમે એક સમયે માત્ર એક ટોસ્ટ બતાવવા જઈ રહ્યાં છો, તો પોઝિશનિંગ શૈલીઓ સીધા જ પર મૂકો .toast.

બુટસ્ટ્રેપ 11 મિનિટ પહેલા
હેલો, વિશ્વ! આ ટોસ્ટ સંદેશ છે.
<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>

વધુ સૂચનાઓ જનરેટ કરતી સિસ્ટમો માટે, રેપિંગ એલિમેન્ટનો ઉપયોગ કરવાનું વિચારો જેથી તેઓ સરળતાથી સ્ટેક કરી શકે.

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

તમે ટોસ્ટને આડા અને/અથવા ઊભી રીતે ગોઠવવા માટે ફ્લેક્સબોક્સ ઉપયોગિતાઓ સાથે પણ ફેન્સી મેળવી શકો છો.

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

ઉપલ્બધતા

ટોસ્ટ્સનો હેતુ તમારા મુલાકાતીઓ અથવા વપરાશકર્તાઓ માટે નાના વિક્ષેપો માટે છે, તેથી સ્ક્રીન રીડર્સ અને સમાન સહાયક તકનીકો ધરાવતા લોકોને મદદ કરવા માટે, તમારે તમારા ટોસ્ટ્સને એક aria-liveપ્રદેશમાં લપેટી લેવું જોઈએ . જીવંત પ્રદેશોમાં ફેરફારો (જેમ કે ટોસ્ટ ઘટકને ઇન્જેક્શન/અપડેટ કરવું) સ્ક્રીન રીડર્સ દ્વારા વપરાશકર્તાના ફોકસને ખસેડવાની અથવા અન્યથા વપરાશકર્તાને વિક્ષેપિત કર્યા વિના આપમેળે જાહેર કરવામાં આવે છે. વધુમાં, aria-atomic="true"શું બદલાયું છે તેની ઘોષણા કરવાને બદલે સમગ્ર ટોસ્ટ હંમેશા સિંગલ (પરમાણુ) એકમ તરીકે જાહેર કરવામાં આવે છે તેની ખાતરી કરવા માટે શામેલ કરો (જે જો તમે ટોસ્ટની સામગ્રીનો માત્ર એક ભાગ અપડેટ કરો છો, અથવા જો સમાન ટોસ્ટ સામગ્રી પ્રદર્શિત કરો છો તો સમસ્યા ઊભી થઈ શકે છે. પછીના સમયે). જો પ્રક્રિયા માટે જરૂરી માહિતી મહત્વપૂર્ણ હોય, દા.ત. ફોર્મમાં ભૂલોની યાદી માટે, તો ચેતવણી ઘટકનો ઉપયોગ કરો.ટોસ્ટને બદલે.

નોંધ કરો કે ટોસ્ટ જનરેટ અથવા અપડેટ થાય તે પહેલાં માર્કઅપમાં લાઇવ પ્રદેશ હાજર હોવો જરૂરી છે . જો તમે ગતિશીલ રીતે બંને એક જ સમયે જનરેટ કરો છો અને તેમને પૃષ્ઠમાં દાખલ કરો છો, તો તે સામાન્ય રીતે સહાયક તકનીકો દ્વારા જાહેર કરવામાં આવશે નહીં.

તમારે સામગ્રીના આધારે roleઅને સ્તરને અનુકૂલિત કરવાની પણ જરૂર છે . aria-liveજો તે એક મહત્વપૂર્ણ સંદેશ છે જેમ કે ભૂલ, ઉપયોગ કરો role="alert" aria-live="assertive", અન્યથા role="status" aria-live="polite"વિશેષતાઓનો ઉપયોગ કરો.

delayજેમ જેમ તમે પ્રદર્શિત કરી રહ્યાં છો તે સામગ્રી બદલાય છે, સમયસમાપ્તિ અપડેટ કરવાની ખાતરી કરો જેથી વપરાશકર્તાઓને ટોસ્ટ વાંચવા માટે પૂરતો સમય મળે.

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

ઉપયોગ કરતી વખતે autohide: false, તમારે વપરાશકર્તાઓને ટોસ્ટને બરતરફ કરવાની મંજૂરી આપવા માટે બંધ બટન ઉમેરવું આવશ્યક છે.

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

જ્યારે તકનીકી રીતે તમારા ટોસ્ટમાં ફોકસેબલ/એક્શનેબલ કંટ્રોલ (જેમ કે વધારાના બટન અથવા લિંક્સ) ઉમેરવાનું શક્ય છે, તો તમારે ટોસ્ટને સ્વતઃ છુપાવવા માટે આવું કરવાનું ટાળવું જોઈએ. જો તમે ટોસ્ટને લાંબો સમય delayસમાપ્ત કરો છો , તો પણ કીબોર્ડ અને સહાયક ટેક્નોલોજી વપરાશકર્તાઓને પગલાં લેવા માટે સમયસર ટોસ્ટ સુધી પહોંચવામાં મુશ્કેલી પડી શકે છે (કારણ કે ટોસ્ટ જ્યારે પ્રદર્શિત થાય ત્યારે ફોકસ પ્રાપ્ત કરતા નથી). જો તમારી પાસે એકદમ વધુ નિયંત્રણો હોવા જોઈએ, તો અમે સાથે ટોસ્ટનો ઉપયોગ કરવાની ભલામણ કરીએ છીએ autohide: false.

સસ

ચલો

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

ઉપયોગ

જાવાસ્ક્રિપ્ટ દ્વારા ટોસ્ટ શરૂ કરો:

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

ટ્રિગર્સ

નીચે દર્શાવ્યા પ્રમાણે ટોસ્ટની અંદરનાdata બટન પરના લક્ષણ સાથે બરતરફી પ્રાપ્ત કરી શકાય છે:

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

અથવા નીચે દર્શાવ્યા પ્રમાણે ટોસ્ટની બહારના બટન પર :data-bs-target

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

વિકલ્પો

વિકલ્પો ડેટા વિશેષતાઓ અથવા JavaScript દ્વારા પસાર કરી શકાય છે. ડેટા એટ્રિબ્યુટ્સ માટે, વિકલ્પ નામને data-bs-, જેમ કે માં ઉમેરો data-bs-animation="".

નામ પ્રકાર ડિફૉલ્ટ વર્ણન
animation બુલિયન true ટોસ્ટ પર CSS ફેડ સંક્રમણ લાગુ કરો
autohide બુલિયન true સ્વતઃ ટોસ્ટ છુપાવો
delay સંખ્યા 5000 ટોસ્ટ છુપાવવામાં વિલંબ (ms)

પદ્ધતિઓ

અસુમેળ પદ્ધતિઓ અને સંક્રમણો

બધી API પદ્ધતિઓ અસુમેળ છે અને સંક્રમણ શરૂ કરે છે . સંક્રમણ શરૂ થતાંની સાથે જ તેઓ કૉલર પાસે પાછા ફરે છે પરંતુ તે સમાપ્ત થાય તે પહેલાં . વધુમાં, સંક્રમણ ઘટક પર પદ્ધતિ કૉલ અવગણવામાં આવશે .

વધુ માહિતી માટે અમારા JavaScript દસ્તાવેજીકરણ જુઓ .

બતાવો

તત્વની ટોસ્ટ દર્શાવે છે. ટોસ્ટ વાસ્તવમાં બતાવવામાં આવે તે પહેલાં (એટલે ​​કે shown.bs.toastઘટના બને તે પહેલાં) કોલરને પરત કરે છે. તમારે આ પદ્ધતિને મેન્યુઅલી કૉલ કરવી પડશે, તેના બદલે તમારું ટોસ્ટ દેખાશે નહીં.

toast.show()

છુપાવો

તત્વના ટોસ્ટને છુપાવે છે. ટોસ્ટ વાસ્તવમાં છુપાયેલ હોય તે પહેલાં (એટલે ​​કે hidden.bs.toastઘટના બને તે પહેલાં) કોલર પાસે પરત આવે છે. જો તમે કર્યું હોય તો તમારે આ પદ્ધતિને મેન્યુઅલી કૉલ કરવી autohideપડશે false.

toast.hide()

નિકાલ

તત્વના ટોસ્ટને છુપાવે છે. તમારું ટોસ્ટ DOM પર રહેશે પરંતુ હવે દેખાશે નહીં.

toast.dispose()

getInstance

સ્થિર પદ્ધતિ જે તમને DOM તત્વ સાથે સંકળાયેલ ટોસ્ટ દાખલા મેળવવા માટે પરવાનગી આપે છે

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

getOrCreateInstance

સ્ટેટિક મેથડ જે તમને DOM એલિમેન્ટ સાથે સંકળાયેલ ટોસ્ટ ઇન્સ્ટન્સ મેળવવાની પરવાનગી આપે છે અથવા જો તે આરંભ ન થયું હોય તો એક નવું બનાવો

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

ઘટનાઓ

ઇવેન્ટનો પ્રકાર વર્ણન
show.bs.toast showજ્યારે ઇન્સ્ટન્સ પદ્ધતિને બોલાવવામાં આવે ત્યારે આ ઇવેન્ટ તરત જ ફાયર થાય છે.
shown.bs.toast જ્યારે ટોસ્ટ વપરાશકર્તાને દૃશ્યક્ષમ બનાવવામાં આવે ત્યારે આ ઇવેન્ટને બરતરફ કરવામાં આવે છે.
hide.bs.toast hideજ્યારે ઇન્સ્ટન્સ મેથડ બોલાવવામાં આવે ત્યારે આ ઇવેન્ટ તરત જ કાઢી નાખવામાં આવે છે.
hidden.bs.toast જ્યારે ટોસ્ટ વપરાશકર્તાથી છુપાયેલું સમાપ્ત થઈ જાય ત્યારે આ ઇવેન્ટને બરતરફ કરવામાં આવે છે.
var myToastEl = document.getElementById('myToast')
myToastEl.addEventListener('hidden.bs.toast', function () {
  // do something...
})