Source

Modal

Kozesa Bootstrap's JavaScript modal plugin okwongera dialogs ku mukutu gwo okufuna lightboxes, okumanyisibwa abakozesa, oba ebirimu custom ddala.

Engeri gye kikola

Nga tonnatandika na Bootstrap's modal component, kakasa nti osoma bino wammanga kuba menu options zaffe zakyuka gye buvuddeko.

  • Modals zizimbibwa ne HTML, CSS, ne JavaScript. Ziteekebwa ku buli kimu ekirala mu kiwandiiko ne ziggyawo okuzingulula okuva ku <body>olwo ebirimu bya modal ne biyiringisibwa mu kifo ky’ekyo.
  • Okunyiga ku modal “backdrop” kijja kuggalawo modal mu ngeri ey’otoma.
  • Bootstrap ewagira eddirisa lya modal limu lyokka omulundi gumu. Nested modals teziwagirwa nga bwe tukkiriza nti zibeera poor user experiences.
  • Modals use position: fixed, oluusi eyinza okuba eyenjawulo katono ku rendering yaayo. Buli lwe kiba kisoboka, teeka HTML yo eya modal mu kifo eky’omutendera ogw’oku ntikko okwewala okutaataaganyizibwa okuyinza okuva mu bintu ebirala. Ojja kusanga ensonga nga okola nesting a .modalmunda mu element endala ennywevu.
  • Nate, olw’oku position: fixed, waliwo okulabula okumu n’okukozesa modals ku byuma ebikozesebwa ku ssimu. Laba ebiwandiiko byaffe ebiwagira browser okumanya ebisingawo.
  • Olw’engeri HTML5 gy’ennyonnyolamu amakulu gaayo, ekintu kya autofocusHTML tekirina kye kikola mu Bootstrap modals. Okusobola okutuuka ku nkola y’emu, kozesa JavaScript ezimu ez’enjawulo:
$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').trigger('focus')
})

Sigala ng’osoma okulaba ebifaananyi n’ebiragiro ebikwata ku nkozesa.

Eby’okulabirako

Wansi waliwo ekyokulabirako kya static modal (ekitegeeza its positionand displayhave been overridden). Mulimu omutwe gwa modal, omubiri gwa modal (ogwetaagisa ku padding), n’omutwe gwa modal (ogw’okwesalirawo). Tusaba okussaamu emitwe gya modal n'ebikolwa eby'okugoba buli lwe kiba kisoboka, oba okuwa ekikolwa ekirala eky'okugoba eky'olwatu.

<div class="modal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </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-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Live demo

Toggle a working modal demo nga onyiga button wansi. Kijja kuseeyeeya wansi era kizike okuva waggulu ku lupapula.

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

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

Okuyiringisiza ebirimu ebiwanvu

Modal bwe zifuuka empanvu ennyo ku viewport oba ekyuma ky'omukozesa, zitambula nga tezikwatagana na lupapula lwennyini. Gezaako demo wansi olabe kye tutegeeza.

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

<!-- Modal -->
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Nga eri wakati mu nneekulungirivu

Okwongerako .modal-dialog-centeredku .modal-dialogokutuuka mu vertikal wakati modal.

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

<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Ebikozesebwa ne popovers

Tooltips ne popovers bisobola okuteekebwa mu modals nga bwekyetaagisa. Modals bweziggalwa, tootips zonna ez’ebikozesebwa ne popovers eziri munda nazo zigobwa mu ngeri ey’otoma.

<div class="modal-body">
  <h5>Popover in a modal</h5>
  <p>This <a href="#" role="button" class="btn btn-secondary popover-test" title="Popover title" data-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="#" class="tooltip-test" title="Tooltip">This link</a> and <a href="#" class="tooltip-test" title="Tooltip">that link</a> have tooltips on hover.</p>
</div>

Nga okozesa ekipande ekiyitibwa grid

Kozesa enkola ya Bootstrap grid munda mu modal nga okola ebisu .container-fluidmunda mu .modal-body. Olwo, kozesa ebika by’enkola ya grid eya bulijjo nga bwe wandikoze awalala wonna.

<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 ml-auto">.col-md-4 .ml-auto</div>
    </div>
    <div class="row">
      <div class="col-md-3 ml-auto">.col-md-3 .ml-auto</div>
      <div class="col-md-2 ml-auto">.col-md-2 .ml-auto</div>
    </div>
    <div class="row">
      <div class="col-md-6 ml-auto">.col-md-6 .ml-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>

Ebirimu eby’enjawulo (modal content).

Olina ekibinja kya buttons nga zonna zisitula modal emu nga zirina ebirimu eby'enjawulo katono? Kozesa event.relatedTargetne HTML data-*attributes (kiyinzika okuyita mu jQuery ) okukyusakyusa ebirimu mu modal okusinziira ku button ki eyanyigibwa.

Wansi waliwo live demo nga egobererwa ekyokulabirako HTML ne JavaScript. Okumanya ebisingawo, soma modal events docs okumanya ebisingawo ku relatedTarget.

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

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">New message</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Recipient:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="form-group">
            <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-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>
$('#exampleModal').on('show.bs.modal', function (event) {
  var button = $(event.relatedTarget) // Button that triggered the modal
  var recipient = button.data('whatever') // Extract info from data-* attributes
  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
  var modal = $(this)
  modal.find('.modal-title').text('New message to ' + recipient)
  modal.find('.modal-body input').val(recipient)
})

Ggyawo ebifaananyi ebirina obulamu

Ku modals ezimala okulabika okusinga okuzikira mu okulaba, ggyawo .fadeekibiina okuva ku modal markup yo.

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

Obugulumivu obw’amaanyi

Singa obugulumivu bwa modal bukyuka nga kiggule, olina okuyita $('#myModal').modal('handleUpdate')okuddamu okutereeza ekifo kya modal singa wabaawo scrollbar okulabika.

Okutuuka ku bantu

Kakasa nti ossaako role="dialog"ne aria-labelledby="...", ng’ojuliza omutwe gwa modal, ku .modal, ne role="document"ku .modal-dialoggwennyini. Okugatta ku ekyo, oyinza okuwa ennyonyola ku mboozi yo eya modal ne aria-describedbyon .modal.

Okuyingiza obutambi bwa YouTube

Okuteeka obutambi bwa YouTube mu modals kyetaagisa JavaScript endala etali mu Bootstrap okuyimiriza otomatiki okuzannya n’ebirala. Laba kino ekiyamba Stack Overflow post okumanya ebisingawo.

Sayizi ez’okwesalirawo

Modals zirina sayizi bbiri ez'okwesalirawo, ezifunibwa okuyita mu kiraasi z'abakyusa okuteekebwa ku .modal-dialog. Sayizi zino ziyingira mu bifo ebimu eby’okumenya okwewala okutambula okw’okwebungulula ku bifo ebifunda eby’okulaba.

<!-- Large modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-lg">Large modal</button>

<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>

<!-- Small modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-sm">Small modal</button>

<div class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>

Enkozesa

Modal plugin ekyusa ebirimu byo ebikwekebwa nga bwe kyetaagisa, okuyita mu data attributes oba JavaScript. Era eyongera .modal-openku <body>to override default scrolling behavior era ekola a .modal-backdropokuwa ekifo eky'okunyiga okugoba modals eziragiddwa nga onyiga ebweru wa modal.

Okuyita mu bikwata ku data

Kozesa modal nga towandiise JavaScript. Teeka data-toggle="modal"ku elementi y'ekifuga, nga button, wamu ne a data-target="#foo"oba href="#foo"okutunuulira modal eyeetongodde okukyusakyusa.

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

Okuyita mu JavaScript

Kuba modal eriko id myModalnga erina layini emu eya JavaScript:

$('#myModal').modal(options)

Eby’okulondako

Ebyokulonda bisobola okuyisibwa nga biyita mu data attributes oba JavaScript. Ku bikwata ku data, ssaako erinnya ly'okulonda ku data-, nga mu data-backdrop="".

Erinnya Okuwandiika Okukosamu Okunnyonnyola
ekifaananyi eky’emabega boolean oba olunyiriri'static' kituufu Mulimu ekintu ekiyitibwa modal-backdrop element. Ekirala, lambika staticku backdrop etaggalawo modal ku click.
ekitabo ekikwata ku kibboodi boolean kituufu Eggalawo modal nga escape key enyigiddwa
tereera boolean kituufu Essira liteeka ku modal nga etandise.
okulaga boolean kituufu Alaga modal nga etandikiddwawo.

Enkola

Enkola ezitakwatagana n’enkyukakyuka

Enkola zonna eza API tezikwatagana era zitandika enkyukakyuka . Zidda eri oyo akubye amangu ddala ng'enkyukakyuka etandise naye nga tennaggwaako . Okugatta ku ekyo, okuyita enkola ku kitundu ekikyukakyuka kujja kubuusibwa amaaso .

Laba ebiwandiiko byaffe ebya JavaScript okumanya ebisingawo.

.modal(options)

Ekola ebirimu byo nga modal. Akkiriza eby'okulonda eby'okwesalirawo object.

$('#myModal').modal({
  keyboard: false
})

.modal('toggle')

Mu ngalo ekyusakyusa modal. Edda eri oyo ayita nga modal tennalagibwa oba okukwekebwa ddala (kwe kugamba nga shown.bs.modaloba hidden.bs.modalekintu tekinnabaawo).

$('#myModal').modal('toggle')

.modal('show')

Mu ngalo aggulawo modal. Edda eri omuyita nga modal tennalagibwa ddala (kwe kugamba nga shown.bs.modalekintu tekinnabaawo).

$('#myModal').modal('show')

.modal('hide')

Mu ngalo akweka modal. Edda eri oyo akubira nga modal tennakwekebwa ddala (kwe kugamba nga hidden.bs.modalekintu tekinnabaawo).

$('#myModal').modal('hide')

.modal('handleUpdate')

Ddamu mu ngalo ekifo kya modal singa obugulumivu bwa modal bukyuka nga kiggule (kwe kugamba mu mbeera nga scrollbar elabika).

$('#myModal').modal('handleUpdate')

.modal('dispose')

Esaanyaawo modal ya elementi.

Ebibaddewo

Bootstrap's modal class eraga ebitonotono ebibaawo olw'okuyunga mu nkola ya modal. Ebintu byonna ebibaawo mu modal bikubwa ku modal yennyini (kwe kugamba ku <div class="modal">).

Ekika ky’Ekibaddewo Okunnyonnyola
okulaga.bs.modal Ekintu kino kikuba amangu ddala nga showenkola ya instance eyitiddwa. Singa kiva ku kunyiga, ekintu ekinyigiddwa kibeerawo ng’eky’obugagga ky’ekintu relatedTargetekibaddewo.
eragiddwa.bs.modal Ekintu kino kikubwa nga modal ekoleddwa okulabika eri omukozesa (ejja kulinda enkyukakyuka za CSS okuggwa). Singa kiva ku kunyiga, ekintu ekinyigiddwa kibeerawo ng’eky’obugagga ky’ekintu relatedTargetekibaddewo.
okukweka.bs.modal Ekintu kino kikubwa amangu ddala nga hideenkola ya instance eyitiddwa.
ekikwekebwa.bs.modal Ekintu kino kikubwa nga modal emaze okukwekebwa okuva eri omukozesa (ejja kulinda enkyukakyuka za CSS okuggwa).
$('#myModal').on('hidden.bs.modal', function (e) {
  // do something...
})