मोडल हें नांव
लायटबॉक्स, वापरपी अधिसुचोवण्यो, वा पुरायपणान सानुकूल सामुग्री खातीर तुमच्या साइटचेर संवाद जोडपाक Bootstrap चें JavaScript मोडल प्लगइन वापरात.
कशें काम करता
Bootstrap च्या मोडल घटकाक सुरवात करचे पयलीं, आमचे मेनू पर्याय हालीं बदलल्यात म्हणून सकयल दिल्लें वाचपाची खात्री करात.
- मोडल एचटीएमएल, सीएसएस, आनी जावास्क्रिप्ट हांणी तयार केल्ले आसात. ते दस्तावेजांतल्या हेर सगळ्या गजालींचेर स्थापन केल्यात आनी तातूंतल्यान स्क्रोल काडून उडयतात
<body>
जेणे करून मोडल सामुग्री ताचे बदला स्क्रोल करता. - मोडल “पार्श्वभूंय” चेर क्लिक केल्यार मोडल आपोआप बंद जातलें.
- बूटस्ट्रॅप एका वेळार फकत एक मोडल विंडो समर्थन करता. नेस्टेड मोडलांक तेंको दिवंक ना कारण आमी मानतात की ते वापरप्याचे वायट अणभव आसात.
- Modals use
position: fixed
, जें केन्ना केन्नाय ताच्या रेंडरींग विशीं मात्शें विशिश्ट आसूं येता. शक्य आसल्यार, हेर घटकां कडल्यान संभाव्य हस्तक्षेप टाळपा खातीर तुमचो मोडल HTML वयल्या पांवड्यावेल्या सुवातेर दवरात. तुमकां.modal
दुसर् या थारावीक घटका भितर एक नेस्ट करतना समस्या येवपाची शक्यताय आसा. - परत एक फावट, कारण
position: fixed
, मोबायल डिव्हायसांचेर मोडल वापरपा कडेन कांय सावधानताय आसात. तपशीलां खातीर आमचे ब्राउझर आदार डॉक्स पळयात. - HTML5 आपली अर्थशास्त्र कशी व्याख्या करता ताका लागून, HTML
autofocus
गुणधर्माचो बूटस्ट्रॅप मोडलांत कसलोच परिणाम जायना. तोच परिणाम मेळोवपाखातीर, कांय सानुकूल जावास्क्रिप्ट वापरात:
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
ह्या घटकाचो एनिमेशन परिणाम prefers-reduced-motion
माध्यम क्वेरीचेर आदारून आसता. आमच्या सुलभताय दस्तावेजीकरणाचो उणो केल्ली गती विभाग पळयात .
डेमो आनी वापर मार्गदर्शक तत्वां खातीर वाचत रावचें.
उदाहरणां
मोडल घटक
सकयल एक स्थिर मोडल उदाहरण आसा (म्हळ्यार ताचें position
आनी display
अधिलिखित केल्यात). मोडल हेडर, मोडल बॉडी ( खातीर गरज आसा padding
), आनी मोडल फूटर (पर्यायी) समाविष्ट आसात. शक्य आसल्यार तुमी डिसमिस कृती सयत मोडल हेडरांचो आस्पाव करचो, वा दुसरी स्पश्ट डिसमिस कृती दिवची अशें आमी मागतात.
<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-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
लायव्ह डेमो
सकयल दिल्लें बटण क्लिक करून काम करपी मोडल डेमो टॉगल करात. तो सकयल सरकतलो आनी पानाच्या वयल्या भागांतल्यान भितर फीको जातलो.
<!-- 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>
लांब सामुग्री स्क्रोल करप
जेन्ना वापरप्याच्या व्ह्यूपोर्ट वा डिव्हायसा खातीर मोडल चड लांब जातात, तेन्ना ते पानाचेरच स्वतंत्रपणान स्क्रोल करतात. आमी कितें म्हणपाक सोदतात तें पळोवपा खातीर सकयल दिल्लो डेमो वापरून पळयात.
<!-- 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>
तुमी स्क्रोल करपाक येवपी मोडलय तयार करूंक शकतात जो मोडल बॉडी स्क्रोल करपाक परवानगी .modal-dialog-scrollable
दिता .modal-dialog
.
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalScrollable">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalScrollable" tabindex="-1" role="dialog" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalScrollableTitle">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-dialog-centered
करपाक to जोडात ..modal-dialog
<!-- 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">×</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>
टूलटिप्स आनी पोपोव्हर्स
गरज पडल्यार टूलटिप्स आनी पोपोव्हर मोडलां भितर दवरूं येतात. जेन्ना मोडल बंद जातात, तेन्ना भितरले खंयचेय टूलटिप्स आनी पॉपओव्हरय आपोआप काडून उडयतात.
<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>
जाळी वापरप
.container-fluid
भितर नेस्ट करून मोडला भितर बूटस्ट्रॅप ग्रिड प्रणालीचो वापर करचो .modal-body
. मागीर, तुमी हेर खंयच्याय सुवातेर करतले तशें सामान्य ग्रिड प्रणाली वर्ग वापरात.
<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>
बदलपी मोडल आशय
बटणांचो एक गट आसा जो सगळे मात्शे वेगळ्या आशयांनी एकूच मोडल ट्रिगर करतात? खंयचें बटण क्लिक केलां ताचेर आदारून मोडलाची आशय बदलपाक वापरात event.relatedTarget
आनी HTML data-*
गुणधर्म ( कदाचित jQuery वरवीं ).
सकयल लायव्ह डेमो आसा आनी ताचे उपरांत उदाहरण HTML आनी JavaScript आसा. चड म्हायती खातीर, हाचेर तपशीलां खातीर मोडल इव्हेंट डॉक्स वाचात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)
})
एनिमेशन बदलात
मोडल फेड-इन एनिमेशन करचे पयलीं चडांत चड रुपांतर स्थिती थारायता, मोडल फेड-इन एनिमेशनाच्या निमाणें $modal-fade-transform
चडांत चड रुपांतर थारायता ..modal-dialog
$modal-show-transform
.modal-dialog
तुमकां देखीक झूम-इन एनिमेशन जाय जाल्यार, तुमी सेट करूंक शकतात $modal-fade-transform: scale(.8)
.
एनिमेशन काडून उडोवप
पळोवपाक फिकट जावचे परस फकत दिसपी मोडलां खातीर, .fade
तुमच्या मोडल मार्कअपांतल्यान वर्ग काडून उडोवचो.
<div class="modal" tabindex="-1" role="dialog" aria-labelledby="..." aria-hidden="true">
...
</div>
गतिशील उंचाय
मोडाल उक्तो आसतना ताची उंचाय बदलल्यार, $('#myModal').modal('handleUpdate')
स्क्रोलबार दिसल्यार मोडालाची सुवात परतून समायोजीत करपाक तुमी कॉल करचो.
सुलभताय
role="dialog"
आनी aria-labelledby="..."
, मोडल शीर्षकाचो संदर्भ दिवन, to , .modal
आनी स्वताक जोडपाची खात्री करात . ते भायर, तुमी तुमच्या मोडल संवादाचें वर्णन on कडेन दिवंक शकतात .role="document"
.modal-dialog
aria-describedby
.modal
युट्युब व्हिडियो एम्बेड करप
YouTube व्हिडियो मोडलांत एम्बेड करपाक आपोआप प्लेबॅक थांबवपाक Bootstrap त नाशिल्ली अतिरिक्त JavaScript आनी हेर जाय. चड म्हायती खातीर हें उपकाराचें स्टॅक ओव्हरफ्लो पोस्ट पळयात .
पर्यायी आकार आसात
मोडलांचे तीन पर्यायी आकार आसतात, जे एक चेर दवरपाक संशोधक वर्गां वरवीं उपलब्ध आसात .modal-dialog
. अरुंद दृश्यपोर्टांचेर आडवे स्क्रोलबार टाळपाखातीर हे आकार कांय ब्रेकपॉइंटांचेर किक इन करतात.
आकार | वर्ग | मोडल चडांत चड-रुंदी |
---|---|---|
ल्हान | .modal-sm |
300px |
डिफॉल्ट | कांयच ना | 500px |
व्हड | .modal-lg |
800px |
अतिरिक्त व्हडलें | .modal-xl |
1140px |
संशोधक वर्ग नाशिल्लो आमचो मुलभूत मोडल “मध्यम” आकाराचो मोडल घडयता.
<!-- Extra large modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-xl">Extra large modal</button>
<div class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
...
</div>
</div>
</div>
<!-- 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-open
करपाक जोडटा आनी मोडला भायर क्लिक करतना दाखयल्ले मोडल काडून उडोवपाखातीर क्लिक क्षेत्र पुरवण करपाक a तयार करता.<body>
.modal-backdrop
डेटा गुणधर्मां वरवीं
Activate a modal without writing JavaScript. Set data-toggle="modal"
on a controller element, like a button, along with a data-target="#foo"
or href="#foo"
to target a specific modal to toggle.
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
Via JavaScript
Call a modal with id myModal
with a single line of JavaScript:
$('#myModal').modal(options)
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-backdrop=""
.
Name | Type | Default | Description |
---|---|---|---|
backdrop | boolean or the string 'static' |
true | Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click. |
keyboard | boolean | true | Closes the modal when escape key is pressed |
focus | boolean | true | Puts the focus on the modal when initialized. |
show | boolean | true | Shows the modal when initialized. |
Methods
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
.modal(options)
Activates your content as a modal. Accepts an optional options object
.
$('#myModal').modal({
keyboard: false
})
.modal('toggle')
Manually toggles a modal. Returns to the caller before the modal has actually been shown or hidden (i.e. before the shown.bs.modal
or hidden.bs.modal
event occurs).
$('#myModal').modal('toggle')
.modal('show')
Manually opens a modal. Returns to the caller before the modal has actually been shown (i.e. before the shown.bs.modal
event occurs).
$('#myModal').modal('show')
.modal('hide')
Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. before the hidden.bs.modal
event occurs).
$('#myModal').modal('hide')
.modal('handleUpdate')
Manually readjust the modal’s position if the height of a modal changes while it is open (i.e. in case a scrollbar appears).
$('#myModal').modal('handleUpdate')
.modal('dispose')
Destroys an element’s modal.
Events
Bootstrap’s modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e. at the <div class="modal">
).
Event Type | Description |
---|---|
show.bs.modal | This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the event. |
shown.bs.modal | वापरप्याक मोडल दिसपाक लायल्यार ही घडणूक फायर जाता (CSS संक्रमण पुराय जावपाची वाट पळयतले). क्लिकाक लागून जाल्यार, क्लिक केल्लो घटक relatedTarget घडणुकेचो गुणधर्म म्हणून उपलब्ध आसा. |
लिपोवप.बी.एस.मोडल | hide दृष्टांत पद्दत कॉल केल्या उपरांत ही घडणूक रोखडीच फायर जाता . |
लिपलां.बीएस.मोडल | वापरप्या कडल्यान मोडल लिपोवप सोंपतकच ही घडणूक फायर जाता (CSS संक्रमण पुराय जावपाची वाट पळयतले). |
$('#myModal').on('hidden.bs.modal', function (e) {
// do something...
})