Rach gu prìomh shusbaint Air adhart gu seòladh docs
Check

Cleachd plugan modal JavaScript Bootstrap gus còmhraidhean a chuir ris an làrach agad airson bogsaichean aotrom, fiosan cleachdaiche, no susbaint gu tur àbhaisteach.

Mar a tha e ag obair

Mus tòisich thu le modal modal Bootstrap, bi cinnteach gun leugh thu na leanas oir tha na roghainnean clàr againn air atharrachadh o chionn ghoirid.

  • Tha modalan air an togail le HTML, CSS, agus JavaScript. Tha iad suidhichte thairis air a h-uile càil eile san sgrìobhainn agus thoir air falbh an scrolla bhon chlàr <body>gus am bi susbaint modal a’ gluasad nan àite.
  • Ma bhriogas tu air a’ mhodal “cùl-raon” dùinidh sin am modal gu fèin-obrachail.
  • Chan eil Bootstrap a’ toirt taic ach do aon uinneag modal aig an aon àm. Chan eil modalan neadachaidh a’ faighinn taic oir tha sinn den bheachd gur e droch eòlas luchd-cleachdaidh a th’ annta.
  • Bidh modalan a’ cleachdadh position: fixed, a dh’ fhaodas uaireannan a bhith beagan sònraichte mu dheidhinn a thoirt seachad. Far a bheil e comasach, cuir do HTML modal ann an suidheachadh àrd-ìre gus casg a chuir air eileamaidean eile a sheachnadh. Is dòcha gum bi duilgheadasan agad nuair a bhios tu a’ neadachadh taobh a- .modalstaigh eileamaid stèidhichte eile.
  • A-rithist, air sgàth position: fixed, tha cuid de uaimhean ann a thaobh a bhith a’ cleachdadh mhodalan air innealan gluasadach. Faic na docaichean taic brabhsair againn airson mion-fhiosrachadh.
  • Air sgàth mar a tha HTML5 a’ mìneachadh a semantics, chan eil buaidh sam bith aig feart HTML ann amautofocus modalan Bootstrap. Gus an aon bhuaidh a choileanadh, cleachd cuid de JavaScript àbhaisteach:
const myModal = document.getElementById('myModal')
const myInput = document.getElementById('myInput')

myModal.addEventListener('shown.bs.modal', () => {
  myInput.focus()
})
Tha buaidh beothalachd na co-phàirt seo an urra ri prefers-reduced-motionceist nam meadhanan. Faic an earrann gluasad lùghdaichte de na sgrìobhainnean ruigsinneachd againn .

Cùm a’ leughadh airson demos agus stiùireadh cleachdaidh.

Eisimpleirean

Gu h-ìosal tha eisimpleir modal statachposition (a’ ciallachadh gu bheil e agus displaygun deach a thoirt thairis). Nam measg tha bann-cinn modal, buidheann modal (riatanach airson padding), agus bonn-coise modal (roghainneil). Bidh sinn ag iarraidh gun cuir thu a-steach cinn-cinn modal le gnìomhan cuir às nuair as urrainnear, no gun toir thu seachad gnìomh diùltadh soilleir eile.

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

Demo beò

Tog demo modal obrach le bhith a’ briogadh air a’ phutan gu h-ìosal. Bidh e a 'sleamhnachadh sìos agus a' seargadh a-steach bho mhullach na duilleige.

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

Cùl-raon statach

Nuair a bhios an cùl-raon air a shuidheachadh gu statach, cha dùin am modal nuair a phutas tu taobh a-muigh dheth. Cliog air a’ phutan gu h-ìosal gus feuchainn air.

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

Sgrolaich susbaint fada

Nuair a dh'fhàsas modalan ro fhada airson sealladh no inneal an neach-cleachdaidh, gluaisidh iad gu neo-eisimeileach bhon duilleag fhèin. Feuch an demo gu h-ìosal gus faicinn dè tha sinn a’ ciallachadh.

Faodaidh tu cuideachd modal scrollable a chruthachadh a leigeas leat a’ bhuidheann modal a sgrùdadh le bhith a’ cur .modal-dialog-scrollableri .modal-dialog.

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

Meadhanach gu dìreach

Cuir .modal-dialog-centeredris .modal-dialoga 'mhodal gu dìreach sa mheadhan.

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

Molaidhean innealan agus popovers

Faodar molaidhean innealan agus popovers a chuir ann am modalan mar a dh’ fheumar. Nuair a bhios modalan dùinte, thèid molaidhean innealan agus popovers sam bith a-staigh a chuir às gu fèin-ghluasadach cuideachd.

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

A 'cleachdadh a' chliath

Cleachd siostam clèithe Bootstrap taobh a-staigh modal le bhith a’ neadachadh .container-fluidtaobh a-staigh an fhaidhle .modal-body. An uairsin, cleachd na clasaichean siostam clèithe àbhaisteach mar a dhèanadh tu an àite sam bith eile.

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

Ag atharrachadh susbaint modal

A bheil dòrlach de phutanan agad a bhrosnaicheas an aon mhodal le susbaint beagan eadar-dhealaichte? Cleachd event.relatedTargetagus buadhan HTMLdata-bs-* gus susbaint a’ mhodail atharrachadh a rèir dè am putan a chaidh a bhriogadh.

Gu h-ìosal tha demo beò air a leantainn le eisimpleir HTML agus JavaScript. Airson tuilleadh fiosrachaidh, leugh na docaichean tachartasan modal airson mion-fhiosrachadh air 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
})

Tog eadar modalan

Tog eadar ioma-mhodalan le beagan suidheachadh ciallach de na data-bs-targetagus data-bs-togglebuadhan. Mar eisimpleir, dh'fhaodadh tu modal ath-shuidheachadh facal-faire a thogail bhon taobh a-staigh de shoidhne a tha fosgailte mar-thà ann am modal. Thoir an aire nach urrainn iomadh modal a bhith fosgailte aig an aon àm - tha an dòigh seo dìreach a’ togail eadar dà mhodal fa leth.

Fosgail a 'chiad modal
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>

Atharraich beothachadh

Bidh an $modal-fade-transformcaochladair a’ dearbhadh staid cruth-atharrachaidh .modal-dialogron bheothachadh modal fade-in, bidh an $modal-show-transformcaochladair a’ dearbhadh an cruth-atharrachadh .modal-dialogaig deireadh a’ bheòthachaidh modal fade-in.

Ma tha thu ag iarraidh mar eisimpleir beòthalachd zoom-in, faodaidh tu $modal-fade-transform: scale(.8).

Thoir air falbh beothachadh

Airson modalan a tha dìreach a’ nochdadh seach a bhith a’ seargadh a-steach ri fhaicinn, thoir air falbh an .fadeclas bhon chomharra modal agad.

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

Àrdan fiùghantach

Ma dh’ atharraicheas àirde modal fhad ‘s a tha e fosgailte, bu chòir dhut fònadh myModal.handleUpdate()gus suidheachadh a’ mhodail a leughadh air eagal ’s gun nochd bàr-scrollaidh.

Ruigsinneachd

Dèan cinnteach gun cuir thu aria-labelledby="...", a’ toirt iomradh air an tiotal modal, gu .modal. A bharrachd air an sin, faodaidh tu cunntas a thoirt air a’ chòmhradh modal agad le aria-describedbyon .modal. Thoir an aire nach fheum thu cur ris role="dialog"oir tha sinn ga chur ris tro JavaScript mu thràth.

Cuir a-steach bhideothan YouTube

Le bhith a’ stèidheachadh bhideothan YouTube ann am modalan feumaidh JavaScript a bharrachd nach eil ann am Bootstrap gus stad a chuir air ath-chluich gu fèin-ghluasadach agus barrachd. Faic am post cuideachail Stack Overflow seo airson tuilleadh fiosrachaidh.

Meudan roghainneil

Tha trì meudan roghainneil aig modalan, rim faighinn tro chlasaichean mion-atharrachaidh airson an cur air faidhle .modal-dialog. Bidh na meudan sin a’ tòiseachadh aig puingean brisidh sònraichte gus barraichean-scrollaidh còmhnard a sheachnadh air puirt-seallaidh nas cumhainge.

Meud Clas Modal leud as motha
Beag .modal-sm 300px
Deònach Chan eil gin 500px
Mòr .modal-lg 800px
Mòr a bharrachd .modal-xl 1140px

Tha am modal bunaiteach againn gun chlas mion-atharrachaidh a’ dèanamh suas modal meud “meadhanach”.

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

Modal làn-sgrìn

Is e ath-chuinge eile an roghainn modal a tha a’ còmhdach sealladh an neach-cleachdaidh a nochdadh, a tha ri fhaighinn tro chlasaichean mion-atharrachaidh a tha air an cur air faidhle .modal-dialog.

Clas Ri fhaotainn
.modal-fullscreen An-còmhnaidh
.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

Caochlaidhean

Air a chur ris ann an v5.2.0

Mar phàirt de dhòigh-obrach caochladairean CSS Bootstrap a tha a’ fàs, bidh modalan a-nis a’ cleachdadh caochladairean CSS ionadail air .modalagus .modal-backdropairson gnàthachadh fìor-ùine leasaichte. Tha luachan airson caochladairean CSS air an suidheachadh tro Sass, agus mar sin tha gnàthachadh Sass fhathast a’ faighinn taic, cuideachd.

  --#{$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};
  

caochladairean Sass

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

Lùb

Bithear a’ cruthachadh modalan làn-sgrìn freagairteach tron $breakpoints​​​​mhapa agus lùb ann am faidhle 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;
      }
    }
  }
}

Cleachdadh

Bidh am plugan modal a’ togail do shusbaint falaichte a rèir iarrtas, tro bhuadhan dàta no JavaScript. Bidh e cuideachd a’ dol thairis air giùlan scrollaidh àbhaisteach agus a’ gineadh a .modal-backdropgus àite cliog a sholarachadh airson a bhith a’ cur às do mhodalan a tha air an sealltainn nuair a phutas tu taobh a-muigh a’ mhodail.

Tro fheartan dàta

Tog suas

Cuir modal an gnìomh gun a bhith a’ sgrìobhadh JavaScript. Suidhich data-bs-toggle="modal"air eileamaid rianadair, mar phutan, còmhla ri a data-bs-target="#foo"no href="#foo"gus amas air modal sònraichte airson gluasad.

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

Cur às

Faodar cur às a dhreuchd leis a’ dataghnè air putan taobh a-staigh a’ mhodail mar a chithear gu h-ìosal:

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

no air putan taobh a-muigh a’ mhodail a’ cleachdadh data-bs-targetmar a chithear gu h-ìosal:

<button type="button" class="btn-close" data-bs-dismiss="modal" data-bs-target="#my-modal" aria-label="Close"></button>
Ged a tha an dà dhòigh air modal a dhiùltadh a’ faighinn taic, cumaibh cuimhne nach eil a bhith a’ cur a-mach à taobh a-muigh modal a’ freagairt ri pàtran deasbaid (modal) Stiùireadh Cleachdaidhean Ùghdarrachaidh ARIA . Dèan seo air do chunnart fhèin.

Air sgàth javascript

Cruthaich modal le aon loidhne de JavaScript:

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

Roghainnean

Leis gum faodar roghainnean a thoirt seachad tro bhuadhan dàta no JavaScript, faodaidh tu ainm roghainn a chuir ri data-bs-, mar ann an data-bs-animation="{value}". Dèan cinnteach gun atharraich thu seòrsa cùis an ainm roghainn bho “ camelCase ” gu “ kebab-case ” nuair a thèid thu seachad air na roghainnean tro bhuadhan dàta. Mar eisimpleir, cleachd data-bs-custom-class="beautifier"an àite data-bs-customClass="beautifier".

Mar Bootstrap 5.2.0, tha na pàirtean uile a’ toirt taic do fheart dàta glèidhte deuchainneachdata-bs-config a dh’ fhaodas rèiteachadh phàirtean sìmplidh a chumail mar shreang JSON. Nuair a tha data-bs-config='{"delay":0, "title":123}'agus data-bs-title="456"buadhan aig eileamaid, bidh an titleluach deireannach 456agus bidh na buadhan dàta fa leth a’ dol thairis air na luachan a chaidh a thoirt seachad air data-bs-config. A bharrachd air an sin, tha na feartan dàta a th’ ann mar-thà comasach air luachan JSON mar data-bs-delay='{"show":0,"hide":150}'.

Ainm Seòrsa Deònach Tuairisgeul
backdrop boolean,'static' true A’ toirt a-steach eileamaid cùl-raon modal. Air neo, sònraich staticairson cùl-raon nach dùin am modal nuair a bhriogas tu.
focus boolean true A’ cur fòcas air a’ mhodal nuair a thèid a thòiseachadh.
keyboard boolean true Dùin am modal nuair a thèid an iuchair teiche a bhrùthadh.

Dòighean-obrach

Modhan asyncronach agus eadar-ghluasadan

Tha a h-uile modh API asyncronach agus tòisichidh iad air eadar- ghluasad . Bidh iad a’ tilleadh chun neach-fios cho luath ‘s a thòisicheas an gluasad ach mus tig e gu crìch . A bharrachd air an sin, cha tèid aire a thoirt do ghairm modh air pàirt gluasaid .

Faic na sgrìobhainnean JavaScript againn airson tuilleadh fiosrachaidh .

Roghainnean seachad

Cuir do shusbaint an gnìomh mar mhodal. A 'gabhail ri roghainnean roghnach object.

const myModal = new bootstrap.Modal('#myModal', {
  keyboard: false
})
Dòigh-obrach Tuairisgeul
dispose A 'sgrios modal eileamaid. (Thoir air falbh dàta air a stòradh air an eileamaid DOM)
getInstance Modh statach a leigeas leat an suidheachadh modal fhaighinn co-cheangailte ri eileamaid DOM.
getOrCreateInstance Dòigh statach a leigeas leat an eisimpleir modal fhaighinn co-cheangailte ri eileamaid DOM, no fear ùr a chruthachadh gun fhios nach deach a thòiseachadh.
handleUpdate Leugh le làimh suidheachadh a’ mhodail ma dh’ atharraicheas àirde a’ mhodail fhad ‘s a tha e fosgailte (ie gun fhios nach nochd bàr-scrollaidh).
hide Le làimh a 'falach modal. Tilleadh chun neach-fios mus deach am modal fhalach (ie mus tachair an hidden.bs.modaltachartas).
show Le làimh a 'fosgladh modal. Tilleadh chun neach-fios mus deach am modal a shealltainn (ie mus tachair an shown.bs.modaltachartas). Cuideachd, faodaidh tu a dhol seachad air eileamaid DOM mar argamaid a gheibhear anns na tachartasan modal (mar an t- relatedTargetseilbh). ( const modalToggle = document.getElementById('toggleMyModal'); myModal.show(modalToggle)i.e.
toggle Tog modal le làimh. Tilleadh chun neach-fios mus deach am modal a shealltainn no fhalach (ie mus tachair an tachartas shown.bs.modalno an hidden.bs.modaltachartas).

Tachartasan

Bidh clas modal Bootstrap a’ nochdadh grunn thachartasan airson a dhol a-steach do ghnìomhachd modal. Tha a h-uile tachartas modal air a losgadh aig a’ mhodal fhèin (ie aig an <div class="modal">).

Tachartas Tuairisgeul
hide.bs.modal Thèid an tachartas seo a losgadh sa bhad nuair a chaidh an hidedòigh eisimpleir a ghairm.
hidden.bs.modal Thèid an tachartas seo a chuir às nuair a tha am modal deiseil a bhith falaichte bhon neach-cleachdaidh (feitheamh ri eadar-ghluasadan CSS a chrìochnachadh).
hidePrevented.bs.modal Tha an tachartas seo air a losgadh nuair a thèid am modal a shealltainn, tha an cùl-raon aige staticagus thèid cliog taobh a-muigh a’ mhodail a dhèanamh. Thèid an tachartas a losgadh cuideachd nuair a thèid an iuchair teicheadh ​​​​a bhrùthadh agus an keyboardroghainn air a shuidheachadh gu false.
show.bs.modal Bidh an tachartas seo a’ losgadh sa bhad nuair showa chanar ris an dòigh eisimpleir. Ma thèid adhbhrachadh le cliog, tha an eileamaid a chaidh a bhriogadh ri fhaighinn mar relatedTargetsheilbh an tachartais.
shown.bs.modal Thèid an tachartas seo a chuir às nuair a bhios am modal ri fhaicinn don neach-cleachdaidh (feitheamh ri eadar-ghluasadan CSS a chrìochnachadh). Ma thèid adhbhrachadh le cliog, tha an eileamaid a chaidh a bhriogadh ri fhaighinn mar relatedTargetsheilbh an tachartais.
const myModalEl = document.getElementById('myModal')
myModalEl.addEventListener('hidden.bs.modal', event => {
  // do something...
})