Adeegso Bootstrap's JavaScript modal plugin si aad ugu darto wada sheekaysiga goobtaada sanduuqyada laydhka, ogeysiisyada isticmaalaha, ama nuxurka gabi ahaanba caadada u ah.

Sida ay u shaqeyso

Kahor intaadan bilaabin qaybta moodeelka Bootstrap, hubi inaad akhrido kuwan soo socda maadaama xulashooyinka liiskayadu ay dhawaan isbeddeleen.

  • Moodooyinka waxaa lagu dhisay HTML, CSS, iyo JavaScript. Waxay dulsaaran yihiin wax kasta oo kale oo ku jira dukumeentiga oo ka saar rog- <body>rog si ay nuxurka modal u rogo.
  • Gujinta habka "backdrop" waxay si toos ah u xiri doontaa habka.
  • Bootstrap waxay taageertaa hal daaqad modal markiiba. Qaababka buulka ah lama taageero maadaama aan aaminsanahay inay yihiin khibrad isticmaale oo liidata.
  • Isticmaalka moodooyinka position: fixed, kuwaas oo mararka qaarkood noqon kara xoogaa gaar ah oo ku saabsan samayntiisa. Mar kasta oo ay suurtogal tahay, dhig qaabka HTML-kaaga meel heer sare ah si aad uga fogaato faragelinta suurtagalka ah ee ka iman karta walxaha kale. Waxay u badan tahay inaad la kulanto arrimo markaad buul .modalku dhex gelinayso shay kale oo go'an.
  • Mar labaad, sababta oo ah position: fixed, waxaa jira qaar ka mid ah digniinaha isticmaalka modal-ka ee aaladaha mobilada. Faahfaahinta ka eeg dokumentiyada taageerada browserkayaga .
  • Sababtoo ah sida HTML5 u qeexayso semantiyadeeda, sifada autofocusHTML wax saameyn ah kuma laha hababka Bootstrap. Si loo gaaro saameyn isku mid ah, isticmaal qaar ka mid ah JavaScript caadadii:
$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').trigger('focus')
})
Saamaynta animation ee qaybtani waxay ku xidhan tahay prefers-reduced-motionwaydiinta warbaahinta. Eeg qaybta dhaqdhaqaaqa la dhimay ee dukumeenti gelitaankeena .

Sii wad akhrinta bandhigyada iyo tilmaamaha isticmaalka.

Tusaalooyinka

Hoos waxaa ku yaal tusaale qaab-dhismeed taagan (macnaheedu waa taas positionoo displaywaa la dhaafay). Waxaa ku jira madaxa modal-ka, modal jirka (loo baahan yahay padding), iyo modal footer (ikhtiyaar ah). Waxaan ku waydiisanaynaa inaad ku darto madax habaysan oo leh ficilo la eryo mar kasta oo ay suurtogal tahay, ama aad bixiso tallaabo kale oo cad oo cayrin ah.

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

Muujinta tooska ah

Beddel qaabka shaqada adoo gujinaya badhanka hoose. Hoos ayay u soo degi doontaa oo waxay ka soo geli doontaa xagga sare ee bogga.

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

Dhabar taagan

Marka gadaasha loo dejiyo inay taagan tahay, modalku ma xidhmi doono marka bannaanka la gujinayo. Guji badhanka hoose si aad isugu daydo

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

<!-- Modal -->
<div class="modal fade" id="staticBackdrop" data-backdrop="static" data-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="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">Understood</button>
      </div>
    </div>
  </div>
</div>

Duubista nuxur dheer

Marka moodalku aad ugu dheeraado aragtida isticmaalaha ama aaladda, waxay u rogaan si madaxbannaan bogga laftiisa. Isku day demo hoose si aad u aragto waxa aanu ula jeedno.

Waxa kale oo aad samayn kartaa hab la-rogrogmi karo kaas oo kuu ogolaanaya in aad rogto modal jirka adiga oo ku .modal-dialog-scrollabledaraya .modal-dialog.

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

Mid toosan

Ku dar .modal-dialog-centeredsi .modal-dialogtoosan u dhexda habka

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

Tilmaamaha qalabka iyo popovers

Tilmaamaha qalabka iyo popovers waxaa lagu dhejin karaa qaab-dhismeedka hadba sida loo baahdo . Marka hababka la xidho, qalab kasta iyo wax-soo-saarka gudaha sidoo kale si toos ah ayaa loo ruqseeyaa.

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

Isticmaalka sharoobada

Ka faa'iidayso nidaamka xabagta Bootstrap gudaha qaab qaab adiga oo buul .container-fluidku dhex jira .modal-body. Kadibna, isticmaal fasalada nidaamka grid-ka caadiga ah sida aad u isticmaali lahayd meel kasta oo kale.

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

Nuxurka moodeelka oo kala duwan

Hayso farabadan badhamada kuwaas oo dhamaantood kicinaya qaab isku mid ah oo ka kooban waxyar oo kala duwan? Isticmaalka event.relatedTargetiyo sifooyinka HTMLdata-* (laga yaabee iyada oo loo marayo jQuery ) si loo kala beddelo waxa ku jira habka iyadoo ku xiran badhanka la gujiyay.

Hoos waxaa ah demo toos ah oo ay ku xigto tusaale HTML iyo JavaScript. Wixii macluumaad dheeraad ah, akhri dukumeentiyada dhacdooyinka modal wixii faahfaahin ah 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" 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="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)
})

Beddel animation

Doorsoomuhu wuxuu $modal-fade-transformgo'aamiyaa xaaladda isbeddelka ka .modal-dialoghor inta aan modal-ku-dhamin animation-ka$modal-show-transform doorsoomuhu wuxuu go'aamiyaa isbeddelka .modal-dialogdhammaadka modal-ku-dhalashada animation-ka.

Haddii aad rabto tusaale ahaan animation-soo-jiid, waxaad dejin kartaa $modal-fade-transform: scale(.8).

Ka saar animation

Qaababka si fudud u muuqda halkii ay ka libdhi lahaayeen si loo eego, ka saar .fadefasalka calaamadaynta qaabkaaga.

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

Dhererka firfircoon

Haddii dhererka modalku is beddelo marka uu furan yahay, waa inaad wacdaa $('#myModal').modal('handleUpdate')si aad u hagaajiso booska modalka haddii ay dhacdo in bir-rogid u muuqato.

Helitaanka

Hubi inaad ku darto aria-labelledby="...", tixraaca cinwaanka modal .modal. Intaa waxaa dheer, waxaad ku siin kartaa sharaxaad ku saabsan wada-hadalka qaab- aria-describedbydhismeedka .modal. Ogsoonow inaadan u baahnayn inaad ku darto role="dialog"maadaama aan mar hore ku darnay JavaScript.

Ku darida fiidiyowyada YouTube

Ku darida fiidyaha YouTube ee moodooyinka waxay u baahan tahay JavaScript dheeri ah oo aan ku jirin Bootstrap si ay si toos ah u joojiso dib u ciyaarida iyo wax ka badan. Fiiri qoraalkan waxtarka leh ee Stack Overflow wixii macluumaad dheeraad ah.

Cabbirrada ikhtiyaariga ah

Moodooyinka waxay leeyihiin saddex cabbir ikhtiyaari ah, oo lagu heli karo fasallada wax ka beddelka si loogu dhejiyo .modal-dialog. Xajmiyadani waxay ka soo galayaan meelo kala goyn gaar ah si ay uga fogaadaan biibitaannada toosan ee meelaha dhuuban ee daawashada.

Cabbirka Fasalka Moodal ballaca ugu badan
Yar .modal-sm 300px
Asal ahaan Midna 500px
Weyn .modal-lg 800px
Aad u weyn .modal-xl 1140px

Qaabkayaga caadiga ah ee aan lahayn wax wax ka beddela ayaa ka kooban cabbirka cabbirka "dhexdhexaad ah".

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

Isticmaalka

Plugin-ka moodeelku wuxuu beddelaa macluumaadkaaga qarsoon ee baahida, iyada oo loo marayo sifooyinka xogta ama JavaScript. Waxa kale oo ay ku darsataa .modal-openin ay meesha <body>ka saarto hab-dhaqanka duubista caadiga ah waxayna soo saartaa a .modal-backdropsi ay u bixiso aag gujis ah oo lagu eryo moodooyinka la soo bandhigay marka la gujinayo meel ka baxsan habka.

Iyada oo loo marayo sifooyinka xogta

Dhaqdhaqaaqa modal adigoon qorin JavaScript. Deji curiyaha data-toggle="modal"kontoroolka, sida badhan, oo ay la socoto a data-target="#foo"ama href="#foo"si aad u beegsato hab gaar ah si aad u leexiso.

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

Iyadoo loo marayo JavaScript

Wac modal leh id myModalleh hal xariiq oo JavaScript ah:

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

Ikhtiyaarada

Ikhtiyaarada waxaa lagu gudbi karaa sifada xogta ama JavaScript. Sifooyinka xogta, ku dheji magaca ikhtiyaarka data-, sida ku jira data-backdrop="".

Magaca Nooca Asal ahaan Sharaxaada
dib-u-dhac boolean ama xadhig'static' run Waxaa ka mid ah curiyaha qaab-dhabeedka. Beddelkeeda, sheeg staticmeel-dambe oo aan xidhin habka gujiska.
kiiboodhka booliyan run Wuxuu xidhaa habka marka furaha baxsadka la riixo
diiradda booliyan run Diirada saara habka marka la bilaabayo.
show booliyan run Muujinaya habka marka la bilaabay.

Hababka

Hababka iyo kala-guurka aan isku midka ahayn

Dhammaan hababka API waa isku mid waxayna bilaabaan kala-guurka . Waxay ku soo noqdaan qofka soo wacaya isla markii uu bilaabmo kala-guurka laakiin ka hor inta uusan dhammaan . Intaa waxaa dheer, hab ku baaqaya in qayb ka beddelka waa la iska indhatiray .

Ka eeg dukumeentiyada JavaScript wixii macluumaad dheeraad ah .

.modal(options)

Waxay u hawlgelisaa macluumaadkaaga qaab habaysan. Aqbala ikhtiyaarka ikhtiyaariga ah object.

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

.modal('toggle')

Gacanta ayaa u roga modal Ku soo noqda qofka soo wacay ka hor inta aan habka dhabta ah la muujin ama aan la qarin (tusaale ka hor inta aanay dhicin shown.bs.modalama hidden.bs.modaldhacdada).

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

.modal('show')

Gacanta ayaa u fura modal Ku soo noqoshada soo wacaha ka hor inta aan qaabka dhabta ah loo muujin (tusaale ka hor intaanay shown.bs.modaldhacdada dhicin).

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

.modal('hide')

Gacanta ayaa u qarisa habka. Ku soo noqoshada soo wacaha ka hor inta aan habka dhabta ah la qarin (ie ka hor intaanay hidden.bs.modaldhacdada dhicin).

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

.modal('handleUpdate')

Gacanta ku hagaaji booska modalka haddii dhererka modalku is beddelo marka uu furan yahay (tusaale waa haddii uu baalku muuqdo).

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

.modal('dispose')

Wuxuu baabi'iyaa habka curiyaha.

Dhacdooyinka

Bootstrap's modal class wuxuu daaha ka qaadaa dhowr dhacdo oo loogu talagalay in lagu xidho shaqaynta modal. Dhammaan dhacdooyinka modal waxa lagu eryaa habka laftiisa (ie at the <div class="modal">).

Nooca Dhacdada Sharaxaada
show.bs.modal Dhacdadani waxay isla markaaba gubataa marka showhabka tusaalaha la yiraahdo. Haddi ay keento gujis, cunsurka la gujiyay ayaa diyaar u ah relatedTargethantida dhacdada.
tusay.bs.modal Dhacdadan waxa la eryaa marka habka loo muujiyo isticmaalaha (waxa ay sugi doontaa inta uu CSS ku wareejinayo dhamaystirka). Haddi ay keento gujis, cunsurka la gujiyay ayaa diyaar u ah relatedTargethantida dhacdada.
qari.bs.modal Dhacdadan ayaa isla markaaba la eryaa marka hidehabka tusaale ahaan loo waco.
qarsoon.bs.modal Dhacdadan waxa la eryaa marka modalku dhammeeyo in laga qariyo isticmaalaha (waxay sugi doontaa inta uu CSS ka gudbayo dhamaystirka).
qariPrevented.bs.modal Dhacdadan waxa la eryaa marka modal-ka la tuso, dhabarkeeduna yahay staticiyo gujin ka baxsan habka ama furaha furaha furaha ayaa la sameeyaa iyadoo la raacayo ikhtiyaarka kiiboodhka ama data-keyboardlagu dejiyay false.
$('#myModal').on('hidden.bs.modal', function (event) {
  // do something...
})