Modal a ni
Bootstrap-a JavaScript modal plugin hmangin i site-ah dialog dah la, lightbox, user notification emaw, custom content kimchang emaw a awm thei ang.
Bootstrap-a modal component i hman tan hmain a hnuaia mi hi chhiar hmasa phawt ang che, tun hnaia kan menu option te a danglam tawh avangin.
- Modal te hi HTML, CSS, leh JavaScript hmanga siam a ni. Document chhunga thil dang zawng zawng chungah an dah a, scroll atang chuan an paih chhuak a,
<body>
chutiang chuan modal content chu a scroll zawk ang. - Modal “backdrop” click chuan modal chu a khar nghal vek ang.
- Bootstrap hian modal window pakhat chauh a support a. Nested modal te hi user experience tha lo tak an nih kan rin avangin an support lo.
- Modals use
position: fixed
, chu chu a rendering chungchangah hian a chang chuan a particular deuh thei. A theih phawt chuan element dangte’n an tihbuai theih loh nan i modal HTML chu top-level position-ah dah la..modal
Fixed element dang chhunga a nest hunah issue i tawk mai thei . - Vawi khat chu, due to
position: fixed
, mobile device-a modal hman chungchangah caveat thenkhat a awm bawk. A chipchiar zawkna chu kan browser support docs ah hian en rawh . - HTML5 hian a semantics a sawifiah dan avang hian HTML
autofocus
attribute hian Bootstrap modal-ah nghawng a nei lo. Chutiang bawka effect nei tur chuan custom JavaScript thenkhat hmang la:
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
Demo leh hman dan tur kaihhruaina chhiar chhunzawm zel ang che.
A hnuaia tarlan te hi static modal entirnan (a awmzia chu its position
and display
have been overridden tihna a ni). A chhungah hian modal header, modal body (a mamawh tur padding
), leh modal footer (optional) te pawh a tel. A theih phawt chuan dismiss action nen modal header te dah tel turin kan ngen a, a nih loh leh dismiss action chiang tak dang pe turin kan ngen bawk.
<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">×</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>
A hnuaia button hi click la, working modal demo chu toggle rawh. A hnuai lam a pan ang a, page chunglam atang chuan a fade in ang.
<!-- 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">×</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>
Modal te chu user viewport emaw device emaw atan a sei lutuk chuan page ngei atanga innghat lovin an scroll thin. Kan sawi tum chu a hnuaia demo hi han en teh.
<!-- 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">×</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>
Add .modal-dialog-centered
to .modal-dialog
ah chuan modal chu vertically center ah dah rawh.
<!-- 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">×</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>
Tooltip leh popover te chu a tul angin modal chhungah dah theih a ni. Modal khar a nih chuan a chhunga tooltip leh popover awm apiang chu automatic in a dismis vek bawk.
<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>
Bootstrap grid system chu modal chhungah hmang la .container-fluid
, .modal-body
. Tichuan, hmun dangah i tih ang bawkin grid system class pangngai te chu hmang ang che.
<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>
Button bunch khat, modal khata trigger vek, content hrang hrang tlem nei? Use event.relatedTarget
leh HTML data-*
attributes ( jQuery kaltlangin pawh ni thei ) hmangin modal chhunga thu awmte chu eng button nge click tih a zirin a danglam thei.
A hnuaiah hian live demo a awm a, chu chu entirnan HTML leh JavaScript a ni. Hriat belh duh chuan modal events docs chhiar la , 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">×</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)
})
En tur fade in ai chuan modal lang mai mai tur tan chuan .fade
i modal markup atang khan class chu paih chhuak rawh.
<div class="modal" tabindex="-1" role="dialog" aria-labelledby="..." aria-hidden="true">
...
</div>
Modal hawn laiin a san zawng a inthlak $('#myModal').modal('handleUpdate')
chuan scrollbar a rawn lang palh hlauh chuan modal awmna tur siamthat leh turin i call tur a ni.
Modal title, to , leh amah ngei pawh reference-in leh , add ngei role="dialog"
ang che . Tin, i modal dialog chungchang sawifiahna chu on hmangin i pe thei bawk.aria-labelledby="..."
.modal
role="document"
.modal-dialog
aria-describedby
.modal
YouTube video modal-a embede tur chuan Bootstrap-a awm lo JavaScript dang a ngai a, chu chuan playback chu automatic-in a titawp thei a, thil dang tam tak a titawp thei bawk. Hrechiang duh tan he Stack Overflow post \angkai tak hi en la .
Modal hian optional size pahnih a nei a, modifier class kaltlangin a .modal-dialog
. Heng size te hi breakpoint thenkhatah an kick in thin a, chu chuan viewport tawi zawka horizontal scrollbar awm loh nan.
<!-- 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>
Modal plugin hian i thup thup chu a mamawh angin a toggle a, data attribute emaw JavaScript hmangin a toggle thei bawk. .modal-open
Tin , <body>
to override default scrolling behavior ah a dah belh bawk a .modal-backdrop
, modal pawn lama click hunah shown modals dismiss theihna tur click area a siam bawk.
JavaScript ziak lovin modal pakhat activate rawh. data-toggle="modal"
Controller element, button ang chi, a data-target="#foo"
or href="#foo"
toggle tur modal bik target tur nen set rawh .
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
myModal
JavaScript line khata id nei modal chu ko rawh :
$('#myModal').modal(options)
Options chu data attribute emaw JavaScript hmangin pass theih a ni. Data attribute atan chuan option hming chu , ah hian append la data-
, data-backdrop=""
.
Hming | Lampang | Hlawhchhamna | Hrilhfiahna |
---|---|---|---|
backdrop a ni | boolean emaw a string emaw a ni'static' |
dik | Modal-backdrop element a awm bawk. static A nih loh leh, click-a modal khar lo backdrop atan specify bawk ang che. |
keyboard hmangin a ziak a | boolean a ni | dik | Escape key i hmet chuan modal a khar thin |
tumbik nei | boolean a ni | dik | Initialized hunah modal ah focus a dah thin. |
lantir | boolean a ni | dik | Initialized hunah modal a lantir. |
Asynchronous method leh inthlak danglamna te
API method zawng zawng hi asynchronous a ni a , transition a tan vek a ni . Transition an tan veleh mahse a tawp hmain call tu hnenah an kir leh thin . Chu bakah, transitioning component-a method call chu ngaihthah a ni ang .
I content chu modal angin a activate thin. A pawm a, optional options a awm object
bawk .
$('#myModal').modal({
keyboard: false
})
Modal pakhat chu manual in a toggle thin. Modal a lan tak tak hma emaw a thup hma emaw (chu chu shown.bs.modal
or hidden.bs.modal
event a thlen hma) caller hnenah a kir leh thin.
$('#myModal').modal('toggle')
Manual takin modal a hawng thin. Modal a lan tak takshown.bs.modal
hmain (chu chu event a thlen hmain ) caller hnenah a kir leh thin.
$('#myModal').modal('show')
Manual takin modal a thup thin. Modal a thup tak tak hmain (chu chu hidden.bs.modal
event a thlen hma) caller hnenah a kir leh thin.
$('#myModal').modal('hide')
Modal hawn laiin a san zawng a inthlak chuan (chu chu scrollbar a rawn lang a nih chuan) modal awmna tur chu manual-in siam \ha leh rawh.
$('#myModal').modal('handleUpdate')
Element pakhat modal a tichhia.
Bootstrap-a modal class hian modal functionality-a hooking-na tur event tlemte a pholang a ni. Modal event zawng zawng hi modal ngeiah (ie at the <div class="modal">
).
Thil thleng chi hrang hrang | Hrilhfiahna |
---|---|
show.bs.modal a ni | show He event hi instance method kan koh chuan a fire nghal vek a ni. Click avanga lo awm a nih chuan click element chu relatedTarget event property atan a awm thei. |
tih a ni.bs.modal | He event hi modal chu user hmuh theiha siam a nih hunah fire a ni (CSS transition zawh hun a nghak ang). Click avanga lo awm a nih chuan click element chu relatedTarget event property atan a awm thei. |
thup.bs.modal a ni | hide He event hi instance method koh a nih chuan a fire nghal a ni. |
thup.bs.modal tih a ni | He event hi modal chu user hnen atanga thup a nih zawh chuan a fire thin (CSS transitions zawh hun a nghak ang). |
$('#myModal').on('hidden.bs.modal', function (e) {
// do something...
})