Tsibela kumxholo ophambili Tsiba uye kukhangelo lwamaxwebhu
Check

Sebenzisa iplagi yemodal ye-Bootstrap yeJavaScript ukongeza iingxoxo kwindawo yakho yeebhokisi ezikhanyayo, izaziso zabasebenzisi, okanye umxholo olungiselelwe ngokupheleleyo.

Ingaba isebenza kanjani

Ngaphambi kokuba uqalise ngecandelo le-modal ye-Bootstrap, qiniseka ukuba ufunda oku kulandelayo njengoko ukhetho lwethu lwemenyu lusanda kutshintsha.

  • Iimodyuli zakhiwe ngeHTML, CSS, kunye neJavaScript. Zibekwe phezu kwayo yonke enye into kuxwebhu kwaye zisuse umqulu ukusuka <body>ukuze umxholo wemodal ujikeleze endaweni yoko.
  • Ukucofa kwi-modal "umva" kuya kuvala ngokuzenzekelayo i-modal.
  • I-Bootstrap ixhasa kuphela ifestile yemodal enye ngexesha. Iimodyuli ezifakwe kwiNgxoxo azixhaswa njengoko sikholelwa ukuba zingamava angalunganga kubasebenzisi.
  • Iimodali zisetyenziswa position: fixed, enokuthi ngamanye amaxesha ibe yinto ethile malunga nonikezelo lwayo. Nanini na xa kunokwenzeka, beka i-modal yakho ye-HTML kwindawo yomgangatho ophezulu ukunqanda ukuphazamiseka okunokubakho kwezinye izinto. Uya kubaleka kwimiba xa ufulela .modalngaphakathi kwenye into emiselweyo.
  • Kwakhona, ngenxa ye position: fixed, kukho imiqolomba ngokusebenzisa iimodyuli kwizixhobo eziphathwayo. Jonga amaxwebhu ethu enkxaso kwisikhangeli ukuze ufumane iinkcukacha.
  • Ngenxa yendlela i-HTML5 eyichaza ngayo i-semantics yayo, uphawu lwe- autofocusHTML alunasiphumo kwiimodyuli zeBootstrap. Ukufezekisa umphumo ofanayo, sebenzisa iJavaScript yesiko:
const myModal = document.getElementById('myModal')
const myInput = document.getElementById('myInput')

myModal.addEventListener('shown.bs.modal', () => {
  myInput.focus()
})
Isiphumo soopopayi seli candelo sixhomekeke prefers-reduced-motionkumbuzo wemidiya. Jonga icandelo leentshukumo ezincitshisiweyo kuxwebhu lwethu lofikelelo .

Qhubeka ufunda iidemos kunye nezikhokelo zokusetyenziswa.

Imizekelo

Apha ngezantsi kukho umzekelo wemodyuli engatshintshiyo (ithetha ukuba yona positionkwaye displayiye yabhalwa ngaphezulu). Okubandakanyiweyo yintloko yemodyuli, umzimba wemodali (ufuneka padding), kunye nefooter yemodali (ukhetho). Sicela ukuba uquke iiheader zemodal ezinezenzo zokugxotha nanini na kunokwenzeka, okanye unikeze esinye isenzo sokugxotha esicacileyo.

<div class="modal" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Idemo ephilayo

Guqula idemo yendlela yokusebenza ngokunqakraza iqhosha elingezantsi. Iza kutyibilika phantsi kwaye iphele ukusuka phezulu ephepheni.

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Umqolo omileyo

Xa i-backdrop isetelwe kwi-static, i-modal ayiyi kuvala xa ucofa ngaphandle kwayo. Cofa iqhosha elingezantsi ukuze uyizame.

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
  Launch static backdrop modal
</button>

<!-- Modal -->
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Understood</button>
      </div>
    </div>
  </div>
</div>

Ukuskrola umxholo omde

Xa iimodyuli zinde kakhulu kwimboniselo yomsebenzisi okanye isixhobo, ziyaskrola ngaphandle kwephepha ngokwalo. Zama idemo engezantsi ukuze ubone ukuba sithetha ukuthini.

Unokwenza kwakhona imodali eskrolekayo evumela ukuskrola umzimba we-modal ngokongeza .modal-dialog-scrollableku .modal-dialog.

<!-- Scrollable modal -->
<div class="modal-dialog modal-dialog-scrollable">
  ...
</div>

Ngokuthe nkqo embindini

Yongeza kumbindi .modal-dialog-centeredothe .modal-dialognkqo wemodali.

<!-- Vertically centered modal -->
<div class="modal-dialog modal-dialog-centered">
  ...
</div>

<!-- Vertically centered scrollable modal -->
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
  ...
</div>

Iingcebiso zezixhobo kunye neepopovers

Iingcebiso zezixhobo kunye neepopovers zinokufakwa kwiimodyuli njengoko zifuneka. Xa iimodyuli zivaliwe, naziphi na iincam zesixhobo kunye neepopovers ngaphakathi nazo ziyalahlwa ngokuzenzekelayo.

<div class="modal-body">
  <h5>Popover in a modal</h5>
  <p>This <a href="#" role="button" class="btn btn-secondary" data-bs-toggle="popover" title="Popover title" data-bs-content="Popover body content is set in this attribute.">button</a> triggers a popover on click.</p>
  <hr>
  <h5>Tooltips in a modal</h5>
  <p><a href="#" data-bs-toggle="tooltip" title="Tooltip">This link</a> and <a href="#" data-bs-toggle="tooltip" title="Tooltip">that link</a> have tooltips on hover.</p>
</div>

Ukusebenzisa igridi

Sebenzisa inkqubo yegridi yeBootstrap ngaphakathi kwemodali ngokuzalela .container-fluidngaphakathi kwe .modal-body. Emva koko, sebenzisa iiklasi zegridi eqhelekileyo njengoko ubuya kwenza naphi na kwenye indawo.

<div class="modal-body">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-4">.col-md-4</div>
      <div class="col-md-4 ms-auto">.col-md-4 .ms-auto</div>
    </div>
    <div class="row">
      <div class="col-md-3 ms-auto">.col-md-3 .ms-auto</div>
      <div class="col-md-2 ms-auto">.col-md-2 .ms-auto</div>
    </div>
    <div class="row">
      <div class="col-md-6 ms-auto">.col-md-6 .ms-auto</div>
    </div>
    <div class="row">
      <div class="col-sm-9">
        Level 1: .col-sm-9
        <div class="row">
          <div class="col-8 col-sm-6">
            Level 2: .col-8 .col-sm-6
          </div>
          <div class="col-4 col-sm-6">
            Level 2: .col-4 .col-sm-6
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Ukutshintsha komxholo wemodyuli

Uneqela lamaqhosha athi onke avuse imodal efanayo enemixholo eyahlukileyo kancinane? Sebenzisa event.relatedTargetkunye neempawu zeHTMLdata-bs-* zokwahluka imixholo yemodal ngokuxhomekeke ekubeni leliphi iqhosha elicofiweyo.

Ngezantsi i-demo ephilayo ilandelwa ngumzekelo we-HTML kunye neJavaScript. Ngolwazi oluthe vetshe, funda amaxwebhu eziganeko zemodal ngeenkcukacha relatedTarget.

html
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@mdo">Open modal for @mdo</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@fat">Open modal for @fat</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@getbootstrap">Open modal for @getbootstrap</button>

<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">New message</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <form>
          <div class="mb-3">
            <label for="recipient-name" class="col-form-label">Recipient:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="mb-3">
            <label for="message-text" class="col-form-label">Message:</label>
            <textarea class="form-control" id="message-text"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>
const exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', event => {
  // Button that triggered the modal
  const button = event.relatedTarget
  // Extract info from data-bs-* attributes
  const recipient = button.getAttribute('data-bs-whatever')
  // If necessary, you could initiate an AJAX request here
  // and then do the updating in a callback.
  //
  // Update the modal's content.
  const modalTitle = exampleModal.querySelector('.modal-title')
  const modalBodyInput = exampleModal.querySelector('.modal-body input')

  modalTitle.textContent = `New message to ${recipient}`
  modalBodyInput.value = recipient
})

Guqula phakathi kweemodeli

Guqula phakathi kweemodyuli ezininzi ngokubekwa kobuchule data-bs-targetkunye data-bs-toggleneempawu. Umzekelo, ungatshintsha imodal yokusetha kwakhona igama lokugqitha ngaphakathi kophawu olusele luvuliwe kwimodal. Nceda uqaphele iimodyuli ezininzi azinakuvulwa ngexesha elinye-le ndlela itshintsha ngokulula phakathi kweemodyuli ezimbini ezahlukeneyo.

Vula imodali yokuqala
html
<div class="modal fade" id="exampleModalToggle" aria-hidden="true" aria-labelledby="exampleModalToggleLabel" tabindex="-1">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalToggleLabel">Modal 1</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        Show a second modal and hide this one with the button below.
      </div>
      <div class="modal-footer">
        <button class="btn btn-primary" data-bs-target="#exampleModalToggle2" data-bs-toggle="modal">Open second modal</button>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="exampleModalToggle2" aria-hidden="true" aria-labelledby="exampleModalToggleLabel2" tabindex="-1">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalToggleLabel2">Modal 2</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        Hide this modal and show the first with the button below.
      </div>
      <div class="modal-footer">
        <button class="btn btn-primary" data-bs-target="#exampleModalToggle" data-bs-toggle="modal">Back to first</button>
      </div>
    </div>
  </div>
</div>
<a class="btn btn-primary" data-bs-toggle="modal" href="#exampleModalToggle" role="button">Open first modal</a>

Guqula oopopayi

Uguqulo $modal-fade-transformlumisela imo yenguqu .modal-dialogyaphambi kwemodal fade-in oopopayi, $modal-show-transforminguqu imisela inguqu .modal-dialogekupheleni kwemodal fade-in oopopayi.

Ukuba ufuna umzekelo u-zoom-in oopopayi, ungaseta $modal-fade-transform: scale(.8).

Susa oopopayi

Kwiimodyuli ezibonakala ngokulula kunokuba ziphele ukubonwa, susa .fadeiklasi kuphawu lwakho lwemodal.

<div class="modal" tabindex="-1" aria-labelledby="..." aria-hidden="true">
  ...
</div>

Ukuphakama okunamandla

Ukuba umphakamo wemodali uyatshintsha ngelixa ivuliwe, kuya kufuneka ufowunele myModal.handleUpdate()ukulungisa indawo yemodali kwimeko yokuskrola.

Ukufikeleleka

Qinisekisa ukuba wongeza aria-labelledby="...", ubhekisa kwisihloko semodal, ku .modal. Ukongeza, unganika inkcazo yencoko yababini yemodal nge aria-describedbykwi .modal. Qaphela ukuba awudingi ukongeza role="dialog"kuba sele songeze ngeJavaScript.

Ifakela iividiyo zikaYouTube

Ukufakela iividiyo zikaYouTube kwiimodyuli kufuna iJavaScript eyongezelelweyo engekho kwiBootstrap ukumisa ngokuzenzekelayo ukudlala nokunye. Bona esi sithuba sokuPhuma kweSitaki siluncedo ukuze ufumane ulwazi oluthe kratya.

Iisayizi ozikhethelayo

Iimodyuli zineesayizi ezintathu ozikhethelayo, ezifumaneka ngeeklasi zesilungisi eziza kubekwa kwi .modal-dialog. Ezi sayizi zikhaba kwiindawo ezithile zokuqhawula ukunqanda iibar zokuskrola ezithe tye kwiindawo zokujonga ezimxinwa.

Ubungakanani Iklasi Modal max-width
Incinci .modal-sm 300px
Ukuhlala kukho Akukho nanye 500px
Enkulu .modal-lg 800px
Inkulu kakhulu .modal-xl 1140px

Imodyuli yethu engagqibekanga ngaphandle kodidi lwesilungisi yenza "phakathi" yesayizi yemodyuli.

<div class="modal-dialog modal-xl">...</div>
<div class="modal-dialog modal-lg">...</div>
<div class="modal-dialog modal-sm">...</div>

IModali yesikrini esigcweleyo

Olunye uqashiso lukhetho lokuveza imodal egquma imboniselo yomsebenzisi, ekhoyo ngeeklasi zesilungisi ezibekwe kwi .modal-dialog.

Iklasi Ubukho
.modal-fullscreen Ngalo lonke ixesha
.modal-fullscreen-sm-down 576px
.modal-fullscreen-md-down 768px
.modal-fullscreen-lg-down 992px
.modal-fullscreen-xl-down 1200px
.modal-fullscreen-xxl-down 1400px
<!-- Full screen modal -->
<div class="modal-dialog modal-fullscreen-sm-down">
  ...
</div>

CSS

Izinto eziguquguqukayo

Ifakwe kwi-v5.2.0

Njengenxalenye yendlela yokuguquguquka kwe-Bootstrap ye-CSS, iimodyuli ngoku zisebenzisa iinguqu ze-CSS zasekhaya .modalkunye .modal-backdropnokuphucula ukwenziwa ngokwezifiso kwexesha lokwenyani. Amaxabiso okuguquguquka kweCSS asetwe ngeSass, ngoko ke ukwenziwa ngokwezifiso kweSass kusaxhaswa, nako.

  --#{$prefix}modal-zindex: #{$zindex-modal};
  --#{$prefix}modal-width: #{$modal-md};
  --#{$prefix}modal-padding: #{$modal-inner-padding};
  --#{$prefix}modal-margin: #{$modal-dialog-margin};
  --#{$prefix}modal-color: #{$modal-content-color};
  --#{$prefix}modal-bg: #{$modal-content-bg};
  --#{$prefix}modal-border-color: #{$modal-content-border-color};
  --#{$prefix}modal-border-width: #{$modal-content-border-width};
  --#{$prefix}modal-border-radius: #{$modal-content-border-radius};
  --#{$prefix}modal-box-shadow: #{$modal-content-box-shadow-xs};
  --#{$prefix}modal-inner-border-radius: #{$modal-content-inner-border-radius};
  --#{$prefix}modal-header-padding-x: #{$modal-header-padding-x};
  --#{$prefix}modal-header-padding-y: #{$modal-header-padding-y};
  --#{$prefix}modal-header-padding: #{$modal-header-padding}; // Todo in v6: Split this padding into x and y
  --#{$prefix}modal-header-border-color: #{$modal-header-border-color};
  --#{$prefix}modal-header-border-width: #{$modal-header-border-width};
  --#{$prefix}modal-title-line-height: #{$modal-title-line-height};
  --#{$prefix}modal-footer-gap: #{$modal-footer-margin-between};
  --#{$prefix}modal-footer-bg: #{$modal-footer-bg};
  --#{$prefix}modal-footer-border-color: #{$modal-footer-border-color};
  --#{$prefix}modal-footer-border-width: #{$modal-footer-border-width};
  
  --#{$prefix}backdrop-zindex: #{$zindex-modal-backdrop};
  --#{$prefix}backdrop-bg: #{$modal-backdrop-bg};
  --#{$prefix}backdrop-opacity: #{$modal-backdrop-opacity};
  

Iinguqu zeSass

$modal-inner-padding:               $spacer;

$modal-footer-margin-between:       .5rem;

$modal-dialog-margin:               .5rem;
$modal-dialog-margin-y-sm-up:       1.75rem;

$modal-title-line-height:           $line-height-base;

$modal-content-color:               null;
$modal-content-bg:                  $white;
$modal-content-border-color:        var(--#{$prefix}border-color-translucent);
$modal-content-border-width:        $border-width;
$modal-content-border-radius:       $border-radius-lg;
$modal-content-inner-border-radius: subtract($modal-content-border-radius, $modal-content-border-width);
$modal-content-box-shadow-xs:       $box-shadow-sm;
$modal-content-box-shadow-sm-up:    $box-shadow;

$modal-backdrop-bg:                 $black;
$modal-backdrop-opacity:            .5;

$modal-header-border-color:         var(--#{$prefix}border-color);
$modal-header-border-width:         $modal-content-border-width;
$modal-header-padding-y:            $modal-inner-padding;
$modal-header-padding-x:            $modal-inner-padding;
$modal-header-padding:              $modal-header-padding-y $modal-header-padding-x; // Keep this for backwards compatibility

$modal-footer-bg:                   null;
$modal-footer-border-color:         $modal-header-border-color;
$modal-footer-border-width:         $modal-header-border-width;

$modal-sm:                          300px;
$modal-md:                          500px;
$modal-lg:                          800px;
$modal-xl:                          1140px;

$modal-fade-transform:              translate(0, -50px);
$modal-show-transform:              none;
$modal-transition:                  transform .3s ease-out;
$modal-scale-transform:             scale(1.02);

Umjikelo

Iimodyuli eziphendulayo zesikrini esigcweleyo ziveliswa $breakpointsngemephu kunye nelophu kwi scss/_modal.scss.

@each $breakpoint in map-keys($grid-breakpoints) {
  $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
  $postfix: if($infix != "", $infix + "-down", "");

  @include media-breakpoint-down($breakpoint) {
    .modal-fullscreen#{$postfix} {
      width: 100vw;
      max-width: none;
      height: 100%;
      margin: 0;

      .modal-content {
        height: 100%;
        border: 0;
        @include border-radius(0);
      }

      .modal-header,
      .modal-footer {
        @include border-radius(0);
      }

      .modal-body {
        overflow-y: auto;
      }
    }
  }
}

Ukusetyenziswa

I-plugin ye-modal iguqula umxholo wakho ofihliweyo kwimfuno, ngeempawu zedatha okanye iJavaScript. Ikwabeka ngaphezulu kokuziphatha kokuskrola okungagqibekanga kwaye yenze .modal-backdropukubonelela ngokucofa indawo yokugxotha iimodyuli ezibonisiweyo xa ucofa ngaphandle kwemodali.

Ngeempawu zedatha

Guqula

Vula imodali ngaphandle kokubhala iJavaScript. Cwangcisa data-bs-toggle="modal"isiqalelo somlawuli, njengeqhosha, kunye ne data-bs-target="#foo"okanye href="#foo"ukujolisa kwindlela ethile yokuguqula.

<button type="button" data-bs-toggle="modal" data-bs-target="#myModal">Launch modal</button>

Gxotha

Ukugxothwa kunokufezekiswa datangophawu olukwiqhosha ngaphakathi kwendlela njengoko kubonisiwe ngezantsi:

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

okanye kwiqhosha elingaphandle kwendlela usebenzisa data-bs-targetnjengoko kubonisiwe ngezantsi:

<button type="button" class="btn-close" data-bs-dismiss="modal" data-bs-target="#my-modal" aria-label="Close"></button>
Ngelixa zombini iindlela zokugxotha imodali zixhaswa, khumbula ukuba ukukhupha ngaphandle kwemodali akuhambelani nencoko yencoko yencoko yababini ye-ARIA yokuSebenzisa ukuBhalisa (i-modal) . Yenza oku ngomngcipheko wakho.

NgeJavaScript

Yenza imodali ngomgca omnye weJavaScript:

const myModal = new bootstrap.Modal(document.getElementById('myModal'), options)
// or
const myModalAlternative = new bootstrap.Modal('#myModal', options)

Iinketho

Njengoko iinketho zinokugqithiswa ngeempawu zedatha okanye iJavaScript, unokongeza igama lokhetho ku data-bs-, njengakwi data-bs-animation="{value}". Qinisekisa ukuba utshintshe uhlobo lwecala legama lokukhetha ukusuka kwi " camelCase " ukuya kwi " kebab-case " xa udlula iinketho ngeempawu zedatha. Umzekelo, sebenzisa data-bs-custom-class="beautifier"endaweni ye- data-bs-customClass="beautifier".

Ukusukela kwi-Bootstrap 5.2.0, onke amacandelo axhasa umlinganiso wedatha ogciniweyo wovavanyodata-bs-config onokubeka uqwalaselo lwecandelo olulula njengomtya we-JSON. Xa into ineempawu data-bs-config='{"delay":0, "title":123}'kunye data-bs-title="456"neempawu, ixabiso lokugqibela titleliya kuba 456kunye neempawu zedatha eyahlukileyo ziya kuwenza ngaphezulu amaxabiso anikiweyo data-bs-config. Ukongeza, iimpawu zedatha ezikhoyo ziyakwazi ukubeka ixabiso le-JSON njenge data-bs-delay='{"show":0,"hide":150}'.

Igama Uhlobo Ukuhlala kukho Inkcazo
backdrop i-boolean,'static' true Ibandakanya i-modal-backdrop element. Kungenjalo, khankanya staticimeko yangasemva engayivaliyo imodal xa ucofa.
focus boolean true Ibeka ugqaliselo kwimodali xa iqaliswa.
keyboard boolean true Ivala imodal xa iqhosha lokubaleka licofa.

Iindlela

Iindlela ze-Asynchronous kunye notshintsho

Zonke iindlela ze-API zi -asynchronous kwaye ziqala utshintsho . Babuyela kumnxeba ngokukhawuleza nje ukuba utshintsho luqalisiwe kodwa ngaphambi kokuba luphele . Ukongeza, ukufowunelwa kwendlela kwicandelo lenguquko kuya kuhoywa .

Jonga uxwebhu lwethu lweJavaScript ngolwazi olungakumbi .

Iinketho zokupasa

Yenza umxholo wakho ube yimodali. Yamkela iinketho ozikhethelayo object.

const myModal = new bootstrap.Modal('#myModal', {
  keyboard: false
})
Indlela Inkcazo
dispose Uyonakalisa imodali yento. (Isusa idatha egciniweyo kwisiqalelo seDOM)
getInstance Indlela engatshintshiyo ekuvumela ukuba ufumane umzekelo wemodal odityaniswa nento yeDOM.
getOrCreateInstance Indlela engatshintshiyo ekuvumela ukuba ufumane umzekelo wemodal onxulunyaniswa nento yeDOM, okanye wenze entsha ukuba ayiqalwanga.
handleUpdate lungisa ngokuzenzela indawo yemodali ukuba umphakamo wemodali uyatshintsha ngelixa ivuliwe (okt xa kuvela ibar yokuskrola).
hide Ufihla imodali ngesandla. Ibuyisela kumnxebi phambi kokuba imodali ifihlwe (okt phambi kokuba hidden.bs.modalisiganeko senzeke).
show Ivula imodali ngesandla. Ubuyela kumnxeba phambi kokuba imodali iboniswe (okt phambi kokuba shown.bs.modalisiganeko senzeke). Kwakhona, ungadlula i-DOM element njengengxabano enokufunyanwa kwiziganeko ze-modal ( relatedTargetnjengepropati). (okt const modalToggle = document.getElementById('toggleMyModal'); myModal.show(modalToggle).
toggle Yenza imodal ngesandla. Ubuyela kumnxeba phambi kokuba imodali iboniswe okanye ifihliwe (okt phambi kokuba isiganeko shown.bs.modalokanye hidden.bs.modalisiganeko senzeke).

Iziganeko

Iklasi ye-modal ye-Bootstrap iveza iminyhadala embalwa yokuqhagamshelwa ekusebenzeni kwe-modal. Zonke iziganeko zemodal ziyagxothwa kwimodali ngokwayo (okt kwi <div class="modal">).

Isiganeko Inkcazo
hide.bs.modal Esi siganeko sigxothwa ngokukhawuleza xa hideindlela yomzekelo ibiziwe.
hidden.bs.modal Esi siganeko sigxothwa xa i-modal igqibile ukufihlwa kumsebenzisi (iya kulinda iinguqu zeCSS ukuba zigqibe).
hidePrevented.bs.modal Esi siganeko sigxothwa xa i-modal iboniswa, i-backdrop yayo statickunye nokuchofoza ngaphandle kwe-modal kwenziwa. Isiganeko siphinde sigxothwe xa isitshixo sokubaleka sicinezelwe kwaye keyboardukhetho lusetelwe ku false.
show.bs.modal Esi siganeko sivutha ngokukhawuleza xa showkubizwa indlela yomzekelo. Ukuba kubangelwa ngonqakrazo, into ecofayo iyafumaneka relatedTargetnjengepropathi yesiganeko.
shown.bs.modal Esi siganeko sigxothwa xa i-modal yenziwe yabonakala kumsebenzisi (iya kulinda i-CSS transitions ukugqiba). Ukuba kubangelwa ngonqakrazo, into ecofayo iyafumaneka relatedTargetnjengepropathi yesiganeko.
const myModalEl = document.getElementById('myModal')
myModalEl.addEventListener('hidden.bs.modal', event => {
  // do something...
})