Source

Modal ƒe nɔnɔme

Zã Bootstrap ƒe JavaScript modal plugin nàtsɔ atsɔ dzeɖonyawo akpe ɖe wò nyatakakadzraɖoƒea ŋu hena kekeli ƒe aɖakawo, zãla ƒe nyatakakawo, alo nyatakaka siwo nètrɔ asi le keŋkeŋ.

Ale si wòwɔa dɔe

Hafi nàdze Bootstrap ƒe modal component gɔme la, kpɔ egbɔ be yexlẽ nusiwo gbɔna elabena míaƒe menu ƒe tiatiawɔblɔɖewo trɔ nyitsɔ laa.

  • Wotsɔ HTML, CSS, kple JavaScript tua mɔnuwo. Woɖo wo ɖe nu bubu ɖesiaɖe dzi le nuŋlɔɖia me eye woɖea agbalẽxatsaxatsa ɖa le la me <body>ale be modal emenyawo naʋuʋu ɖe eteƒe.
  • Ne èzi modal “backdrop” dzi la, axe mɔdal la le eɖokui si.
  • Bootstrap doa alɔ modal fesre ɖeka ko le ɣeyiɣi ɖeka me. Womedoa alɔ nested modals o elabena míexɔe se be wonye zãla ƒe nuteƒekpɔkpɔ gbegblẽwo.
  • Modals zãa position: fixed, si ate ŋu anye etɔxɛ vie ɣeaɖewoɣi le eƒe gɔmeɖeɖe ŋu. Ɣesiaɣi si wòanya wɔ la, da wò modal HTML ɖe teƒe si le dziƒo be nàƒo asa na nusiwo ate ŋu ado kplamatse nu bubuwo. Anɔ eme be àdo go kuxiwo ne èle atɔ wɔm .modalle nu bubu si woɖo ɖi me.
  • Le afisia hã la, le position: fixed, nuxlɔ̃ame aɖewo li le modals zazã le asitelefonwo dzi ŋu. Kpɔ míaƒe browser support docs hena numeɖeɖe bubuwo.
  • Le alesi HTML5 ɖea eƒe gɔmesese gɔmee ta la, HTML autofocusnɔnɔmea mekpɔa ŋusẽ aɖeke ɖe Bootstrap modals dzi o. Be nàkpɔ ŋusẽ ma ke la, zã JavaScript aɖewo siwo wowɔ ɖe ɖoɖo nu:
$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').trigger('focus')
})

Yi edzi nànɔ nu xlẽm hena wɔwɔfiawo kple zazã ŋuti mɔfiamewo.

Kpɔɖeŋuwo

Le ete la, static modal kpɔɖeŋu (si gɔmee nye eƒe positionkple displaywoɖe asi le wo ŋu). Nusiwo le emee nye modal ta, modal ŋutilã (si hiã na padding), kple modal afɔti (si nye tiatia). Míele biabiam be nàde modal headers kple dismiss actions ɣesiaɣi si wòanya wɔ, alo nàna dismiss action bubu si me kɔ.

<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-primary">Save changes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

Live demo ƒe wɔwɔfia

Trɔ asi le modal demo si le dɔ wɔm ŋu to asiƒoƒo ɖe dzesi si le ete la dzi. Aɖiɖi ɖe anyi eye wòaɖiɖi tso axaa tame.

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

Nyatakaka didiwo ʋuʋu

Ne modals didi akpa na zãla ƒe nukpɔkpɔ alo mɔ̃a la, woʋuna le wo ɖokui si le axaa ŋutɔ gbɔ. Te demo si le ete la kpɔ be nàkpɔ nusi míedi be yeagblɔ.

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

Le titina le tsitrenu

Tsɔe kpe ɖe eŋu .modal-dialog-centeredbe .modal-dialogwòaɖo modal la titina le tsitrenu.

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

Dɔwɔnu ƒe aɖaŋuɖoɖowo kple popovers

Woate ŋu atsɔ dɔwɔnu ƒe aɖaŋuɖoɖowo kple popovers ade modals me ne ehiã. Ne wotu modals la, woɖea dɔwɔnu ƒe aɖaŋuɖoɖo ɖesiaɖe kple popovers ɖesiaɖe si le eme hã ɖa le eɖokui si.

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

Grid la zazã

Zã Bootstrap grid system le modal me to nesting .container-fluidle .modal-body. Emegbe, zã grid system ƒe klass siwo sɔ la abe alesi nàwɔe le teƒe bubu ɖesiaɖe ene.

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

Modal ƒe emenyawo ƒe tɔtrɔ

Ðe abɔtawo ƒe ha aɖe si katã ʋãa modal ɖeka si me emenyawo to vovo vie la le asiwòa? Zã event.relatedTargetkple HTML data-*nɔnɔmewo (ɖewohĩ to jQuery dzi ) tsɔ trɔ asi le modal la me nyawo ŋu le abɔta si dzi wozi nu.

Le ete la, live demo si kplɔe ɖo kple kpɔɖeŋu HTML kple JavaScript. Ne èdi nyatakaka bubuwo la, xlẽ modal events docs hena numeɖeɖe tsitotsito le 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)
})

Ðe nɔnɔmetata siwo me woɖea nɔnɔmetatawo le la ɖa

Le modals siwo dzena ko tsɔ wu be woadzo le eme be woakpɔ la, ɖe .fadeklass la ɖa le wò modal markup la me.

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

Kɔkɔme siwo ŋu ŋusẽ le

Ne modal ƒe kɔkɔme trɔ esime wòle ʋuʋu la, ele be nàyɔ $('#myModal').modal('handleUpdate')be nàtrɔ asi le modal la ƒe nɔƒe ŋu nenye be agbalẽxatsaxatsa aɖe adze.

Mɔnukpɔkpɔwo ƒe Mɔnukpɔkpɔ

Kpɔ egbɔ be yetsɔ role="dialog"kple aria-labelledby="...", kpe ɖe modal ƒe tanya ŋu, ɖe .modal, kple role="document"ɖe .modal-dialogeya ŋutɔ ŋu. Tsɔ kpe ɖe eŋu la, àte ŋu ana wò modal dialog ƒe numeɖeɖe kple aria-describedbyon .modal.

YouTube videowo dede eme

YouTube videowo dede modals me bia JavaScript bubu siwo mele Bootstrap me o be wòadzudzɔ ƒoƒo le eɖokui si kple bubuwo. Kpɔ Stack Overflow ƒe nyatakaka sia si kpena ɖe ame ŋu hena nyatakaka bubuwo.

Agbɔsɔsɔme siwo woate ŋu atia

Modals ƒe lolome eve le wo ɖokui si, siwo li to modifier classes dzi be woatsɔ wo ade .modal-dialog. Agbɔsɔsɔ siawo dzea egɔme le teƒe aɖewo be woaƒo asa na agbalẽxatsaxatsa siwo le tsia dzi le nukpɔkpɔ siwo le gbadzaa wu dzi.

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

Zãzã

Modal plugin la trɔa wò nyatakaka ɣaɣlawo ne wobiae, to nyatakaka ƒe nɔnɔmewo alo JavaScript dzi. Egatsɔa kpe .modal-openɖe <body>be woaɖe asi le ʋuʋudedi ƒe nuwɔna si woɖo ɖi ŋu eye wòwɔa a .modal-backdropbe woana teƒe si woate ŋu aƒo nu le hena asiɖeɖe le modal siwo woɖe fia ŋu ne wole asi ƒom le modal la godo.

To nyatakaka ƒe nɔnɔmewo dzi

Wɔ modal aɖe ŋudɔ JavaScript maŋlɔ o. Ðoe data-toggle="modal"ɖe dziɖunu ƒe akpa aɖe dzi, abe abɔta ene, kpakple data-target="#foo"alo href="#foo"be nàɖo taɖodzinu na modal aɖe koŋ be wòatrɔ.

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

To JavaScript dzi

Yɔ modal si si id myModalle kple JavaScript ƒe fli ɖeka:

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

Tiatiawɔblɔɖewo

Woateŋu atsɔ tiatiawɔblɔɖewo ato nyatakaka ƒe nɔnɔmewo alo JavaScript dzi. Le nyatakaka ƒe nɔnɔmewo gome la, tsɔ tiatia ƒe ŋkɔ kpe ɖe data-, abe alesi wòle le data-backdrop="".

Ŋkɔ Ƒomevi Gᴐmedzeƒe Nuɖᴐɖᴐ
megbenyawo boolean alo kaƒoƒoa'static' nyateƒe Modal-backdrop ƒe akpa aɖe hã le eme. Alo, gblɔ staticna megbenya si metua modal le ʋuʋu dzi o.
keyboard dzi boolean ƒe ƒuƒoƒo nyateƒe Doa modal la ne wozi escape key dzi
nu kpɔkpɔ boolean ƒe ƒuƒoƒo nyateƒe Etsɔa susu ɖoa modal la ŋu ne wodze egɔme.
ɖe fia boolean ƒe ƒuƒoƒo nyateƒe Fia modal la ne wodze egɔme.

Mɔnuwo

Mɔnu siwo mewɔ ɖeka kple ɣeyiɣi aɖeke o kple tɔtrɔwo

API mɔnuwo katã nye asynchronous eye wodzea tɔtrɔ gɔme . Wotrɔna yia ame si le ka ƒom na la gbɔ ne wonya dze tɔtrɔa gɔme ko gake hafi wòwu enu . Tsɔ kpe ɖe eŋu la, woaŋe aɖaba aƒu mɔnu ƒe yɔyɔ aɖe dzi le akpa si le tɔtrɔm dzi .

Kpɔ míaƒe JavaScript nuŋlɔɖiwo hena nyatakaka bubuwo.

.modal(options)

Ewɔa wò nyatakakawo ŋudɔ abe modal ene. Lɔ̃ ɖe tiatia siwo woate ŋu awɔ le wo ɖokui si dzi object.

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

.modal('toggle')

Asitɔtrɔ le modal aɖe ŋu. Trɔ yi yɔla gbɔ hafi woɖe modal la fia ŋutɔŋutɔ alo ɣlae (si nye hafi shown.bs.modalalo hidden.bs.modalnudzɔdzɔa nadzɔ).

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

.modal('show')

Eʋua modal aɖe kple asi. Trɔ yi yɔla gbɔ hafi woɖe modal la fia ŋutɔŋutɔ (si nye hafi shown.bs.modalnudzɔdzɔa nadzɔ).

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

.modal('hide')

Asi ɣlaa modal aɖe. Trɔ yi yɔla gbɔ hafi woɣla modal la ŋutɔŋutɔ (si nye hafi hidden.bs.modalnudzɔdzɔa nadzɔ).

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

.modal('handleUpdate')

Trɔ asi le modal ƒe nɔƒe ŋu kple asi ne modal ƒe kɔkɔme trɔ esime wòle ʋuʋu (si fia nenye be agbalẽxatsaxatsa aɖe dze).

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

.modal('dispose')

Egblẽa nu le element aɖe ƒe modal ŋu.

Nudzɔdzɔwo

Bootstrap ƒe modal klass ɖea nudzɔdzɔ ʋee aɖewo ɖe go na hooking ɖe modal dɔwɔwɔ me. Woda tu modal nudzɔdzɔwo katã ɖe modal la ŋutɔ dzi (si nye le <div class="modal">).

Nudzɔdzɔ Ƒomevi Nuɖᴐɖᴐ
ɖee fia.bs.modal Nudzɔdzɔ sia doa dzo enumake ne woyɔ showkpɔɖeŋu mɔnu la. Ne ʋuʋu gbɔe wòtso la, nusi wozi la li abe relatedTargetnudzɔdzɔa ƒe nɔnɔme ene.
woɖe fia.bs.modal Woɖea nudzɔdzɔ sia ne wowɔ modal la be wòadze na zãla (alala be CSS ƒe tɔtrɔwo nawu enu). Ne ʋuʋu gbɔe wòtso la, nusi wozi la li abe relatedTargetnudzɔdzɔa ƒe nɔnɔme ene.
ɣla.bs.modal Woɖea nudzɔdzɔ sia ɖa enumake ne woyɔ hideinstance mɔnu la.
ɣaɣla.bs.modal Woɖea nudzɔdzɔ sia ne wowu modal la ɣla ɖe zãla la nu (alala be CSS ƒe tɔtrɔwo nawu enu).
$('#myModal').on('hidden.bs.modal', function (e) {
  // do something...
})