25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

modal.html 16 KiB

3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <div class="bs-docs-section">
  2. <h1 id="modals" class="page-header">Modals <small>modal.js</small></h1>
  3. <p>Modals are streamlined, but flexible, dialog prompts with the minimum required functionality and smart defaults.</p>
  4. <div class="bs-callout bs-callout-warning" id="callout-stacked-modals">
  5. <h4>Overlapping modals not supported</h4>
  6. <p>Be sure not to open a modal while another is still visible. Showing more than one modal at a time requires custom code.</p>
  7. </div>
  8. <div class="bs-callout bs-callout-warning" id="callout-modal-markup-placement">
  9. <h4>Modal markup placement</h4>
  10. <p>Always try to place a modal's HTML code in a top-level position in your document to avoid other components affecting the modal's appearance and/or functionality.</p>
  11. </div>
  12. <div class="bs-callout bs-callout-warning">
  13. <h4>Mobile device caveats</h4>
  14. <p>There are some caveats regarding using modals on mobile devices. <a href="../getting-started/#support-fixed-position-keyboards">See our browser support docs</a> for details.</p>
  15. </div>
  16. <p><strong class="text-danger">Due to how HTML5 defines its semantics, the <code>autofocus</code> HTML attribute has no effect in Bootstrap modals.</strong></p>
  17. <h2 id="modals-examples">Examples</h2>
  18. <h3>Static example</h3>
  19. <p>A rendered modal with header, body, and set of actions in the footer.</p>
  20. <div class="bs-example bs-example-modal">
  21. <div class="modal">
  22. <div class="modal-dialog">
  23. <div class="modal-content">
  24. <div class="modal-header">
  25. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  26. <h4 class="modal-title">Modal title</h4>
  27. </div>
  28. <div class="modal-body">
  29. <p>One fine body&hellip;</p>
  30. </div>
  31. <div class="modal-footer">
  32. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  33. <button type="button" class="btn btn-primary">Save changes</button>
  34. </div>
  35. </div><!-- /.modal-content -->
  36. </div><!-- /.modal-dialog -->
  37. </div><!-- /.modal -->
  38. </div><!-- /example -->
  39. {% highlight html %}
  40. <div class="modal fade">
  41. <div class="modal-dialog">
  42. <div class="modal-content">
  43. <div class="modal-header">
  44. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  45. <h4 class="modal-title">Modal title</h4>
  46. </div>
  47. <div class="modal-body">
  48. <p>One fine body&hellip;</p>
  49. </div>
  50. <div class="modal-footer">
  51. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  52. <button type="button" class="btn btn-primary">Save changes</button>
  53. </div>
  54. </div><!-- /.modal-content -->
  55. </div><!-- /.modal-dialog -->
  56. </div><!-- /.modal -->
  57. {% endhighlight %}
  58. <h3>Live demo</h3>
  59. <p>Toggle a modal via JavaScript by clicking the button below. It will slide down and fade in from the top of the page.</p>
  60. <!-- sample modal content -->
  61. <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  62. <div class="modal-dialog">
  63. <div class="modal-content">
  64. <div class="modal-header">
  65. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  66. <h4 class="modal-title" id="myModalLabel">Modal title</h4>
  67. </div>
  68. <div class="modal-body">
  69. <h4>Text in a modal</h4>
  70. <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p>
  71. <h4>Popover in a modal</h4>
  72. <p>This <a href="#" role="button" class="btn btn-default popover-test" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">button</a> should trigger a popover on click.</p>
  73. <h4>Tooltips in a modal</h4>
  74. <p><a href="#" class="tooltip-test" title="Tooltip">This link</a> and <a href="#" class="tooltip-test" title="Tooltip">that link</a> should have tooltips on hover.</p>
  75. <hr>
  76. <h4>Overflowing text to show scroll behavior</h4>
  77. <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
  78. <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
  79. <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
  80. <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
  81. <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
  82. <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
  83. <p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
  84. <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
  85. <p>Aenean lacinia bibendum nulla sed consectetur. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Donec ullamcorper nulla non metus auctor fringilla.</p>
  86. </div>
  87. <div class="modal-footer">
  88. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  89. <button type="button" class="btn btn-primary">Save changes</button>
  90. </div>
  91. </div><!-- /.modal-content -->
  92. </div><!-- /.modal-dialog -->
  93. </div><!-- /.modal -->
  94. <div class="bs-example" style="padding-bottom: 24px;">
  95. <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  96. Launch demo modal
  97. </button>
  98. </div><!-- /example -->
  99. {% highlight html %}
  100. <!-- Button trigger modal -->
  101. <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  102. Launch demo modal
  103. </button>
  104. <!-- Modal -->
  105. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  106. <div class="modal-dialog">
  107. <div class="modal-content">
  108. <div class="modal-header">
  109. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  110. <h4 class="modal-title" id="myModalLabel">Modal title</h4>
  111. </div>
  112. <div class="modal-body">
  113. ...
  114. </div>
  115. <div class="modal-footer">
  116. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  117. <button type="button" class="btn btn-primary">Save changes</button>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. {% endhighlight %}
  123. <div class="bs-callout bs-callout-warning">
  124. <h4>Make modals accessible</h4>
  125. <p>Be sure to add <code>role="dialog"</code> to <code>.modal</code>, <code>aria-labelledby="myModalLabel"</code> attribute to reference the modal title, and <code>aria-hidden="true"</code> to tell assistive technologies to skip the modal's DOM elements.</p>
  126. <p>Additionally, you may give a description of your modal dialog with <code>aria-describedby</code> on <code>.modal</code>.</p>
  127. </div>
  128. <div class="bs-callout bs-callout-info">
  129. <h4>Embedding YouTube videos</h4>
  130. <p>Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. <a href="http://stackoverflow.com/questions/18622508/bootstrap-3-and-youtube-in-modal">See this helpful Stack Overflow post</a> for more information.</p>
  131. </div>
  132. <h2 id="modals-sizes">Optional sizes</h2>
  133. <p>Modals have two optional sizes, available via modifier classes to be placed on a <code>.modal-dialog</code>.</p>
  134. <div class="bs-example">
  135. <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>
  136. <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">Small modal</button>
  137. </div>
  138. {% highlight html %}
  139. <!-- Large modal -->
  140. <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>
  141. <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  142. <div class="modal-dialog modal-lg">
  143. <div class="modal-content">
  144. ...
  145. </div>
  146. </div>
  147. </div>
  148. <!-- Small modal -->
  149. <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">Small modal</button>
  150. <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  151. <div class="modal-dialog modal-sm">
  152. <div class="modal-content">
  153. ...
  154. </div>
  155. </div>
  156. </div>
  157. {% endhighlight %}
  158. <!-- Modal content for the above example -->
  159. <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  160. <div class="modal-dialog modal-lg">
  161. <div class="modal-content">
  162. <div class="modal-header">
  163. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  164. <h4 class="modal-title" id="myLargeModalLabel">Large modal</h4>
  165. </div>
  166. <div class="modal-body">
  167. ...
  168. </div>
  169. </div><!-- /.modal-content -->
  170. </div><!-- /.modal-dialog -->
  171. </div><!-- /.modal -->
  172. <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  173. <div class="modal-dialog modal-sm">
  174. <div class="modal-content">
  175. <div class="modal-header">
  176. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  177. <h4 class="modal-title" id="mySmallModalLabel">Small modal</h4>
  178. </div>
  179. <div class="modal-body">
  180. ...
  181. </div>
  182. </div><!-- /.modal-content -->
  183. </div><!-- /.modal-dialog -->
  184. </div><!-- /.modal -->
  185. <h2 id="modals-remove-animation">Remove animation</h2>
  186. <p>For modals that simply appear rather than fade in to view, remove the <code>.fade</code> class from your modal markup.</p>
  187. {% highlight html %}
  188. <div class="modal" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
  189. ...
  190. </div>
  191. {% endhighlight %}
  192. <h2 id="modals-usage">Usage</h2>
  193. <p>The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds <code>.modal-open</code> to the <code>&lt;body&gt;</code> to override default scrolling behavior and generates a <code>.modal-backdrop</code> to provide a click area for dismissing shown modals when clicking outside the modal.</p>
  194. <h3>Via data attributes</h3>
  195. <p>Activate a modal without writing JavaScript. Set <code>data-toggle="modal"</code> on a controller element, like a button, along with a <code>data-target="#foo"</code> or <code>href="#foo"</code> to target a specific modal to toggle.</p>
  196. {% highlight html %}
  197. <button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
  198. {% endhighlight %}
  199. <h3>Via JavaScript</h3>
  200. <p>Call a modal with id <code>myModal</code> with a single line of JavaScript:</p>
  201. {% highlight js %}$('#myModal').modal(options){% endhighlight %}
  202. <h3>Options</h3>
  203. <p>Options can be passed via data attributes or JavaScript. For data attributes, append the option name to <code>data-</code>, as in <code>data-backdrop=""</code>.</p>
  204. <div class="table-responsive">
  205. <table class="table table-bordered table-striped">
  206. <thead>
  207. <tr>
  208. <th style="width: 100px;">Name</th>
  209. <th style="width: 50px;">type</th>
  210. <th style="width: 50px;">default</th>
  211. <th>description</th>
  212. </tr>
  213. </thead>
  214. <tbody>
  215. <tr>
  216. <td>backdrop</td>
  217. <td>boolean or the string <code>'static'</code></td>
  218. <td>true</td>
  219. <td>Includes a modal-backdrop element. Alternatively, specify <code>static</code> for a backdrop which doesn't close the modal on click.</td>
  220. </tr>
  221. <tr>
  222. <td>keyboard</td>
  223. <td>boolean</td>
  224. <td>true</td>
  225. <td>Closes the modal when escape key is pressed</td>
  226. </tr>
  227. <tr>
  228. <td>show</td>
  229. <td>boolean</td>
  230. <td>true</td>
  231. <td>Shows the modal when initialized.</td>
  232. </tr>
  233. <tr>
  234. <td>remote</td>
  235. <td>path</td>
  236. <td>false</td>
  237. <td>
  238. <p><span class="text-danger">This option is deprecated since v3.2.1 and will be removed in v4.</span> We recommend instead using client-side templating or a data binding framework, or calling <a href="http://api.jquery.com/load/">jQuery.load</a> yourself.</p>
  239. <p>If a remote URL is provided, <strong>content will be loaded one time</strong> via jQuery's <code>load</code> method and injected into the <code>.modal-content</code> div. If you're using the data-api, you may alternatively use the <code>href</code> attribute to specify the remote source. An example of this is shown below:</p>
  240. {% highlight html %}
  241. <a data-toggle="modal" href="remote.html" data-target="#modal">Click me</a>
  242. {% endhighlight %}
  243. </td>
  244. </tr>
  245. </tbody>
  246. </table>
  247. </div><!-- /.table-responsive -->
  248. <h3>Methods</h3>
  249. <h4>.modal(options)</h4>
  250. <p>Activates your content as a modal. Accepts an optional options <code>object</code>.</p>
  251. {% highlight js %}
  252. $('#myModal').modal({
  253. keyboard: false
  254. })
  255. {% endhighlight %}
  256. <h4>.modal('toggle')</h4>
  257. <p>Manually toggles a modal. <strong>Returns to the caller before the modal has actually been shown or hidden</strong> (i.e. before the <code>shown.bs.modal</code> or <code>hidden.bs.modal</code> event occurs).</p>
  258. {% highlight js %}$('#myModal').modal('toggle'){% endhighlight %}
  259. <h4>.modal('show')</h4>
  260. <p>Manually opens a modal. <strong>Returns to the caller before the modal has actually been shown</strong> (i.e. before the <code>shown.bs.modal</code> event occurs).</p>
  261. {% highlight js %}$('#myModal').modal('show'){% endhighlight %}
  262. <h4>.modal('hide')</h4>
  263. <p>Manually hides a modal. <strong>Returns to the caller before the modal has actually been hidden</strong> (i.e. before the <code>hidden.bs.modal</code> event occurs).</p>
  264. {% highlight js %}$('#myModal').modal('hide'){% endhighlight %}
  265. <h3>Events</h3>
  266. <p>Bootstrap's modal class exposes a few events for hooking into modal functionality.</p>
  267. <div class="table-responsive">
  268. <table class="table table-bordered table-striped">
  269. <thead>
  270. <tr>
  271. <th style="width: 150px;">Event Type</th>
  272. <th>Description</th>
  273. </tr>
  274. </thead>
  275. <tbody>
  276. <tr>
  277. <td>show.bs.modal</td>
  278. <td>This event fires immediately when the <code>show</code> instance method is called. If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td>
  279. </tr>
  280. <tr>
  281. <td>shown.bs.modal</td>
  282. <td>This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the <code>relatedTarget</code> property of the event.</td>
  283. </tr>
  284. <tr>
  285. <td>hide.bs.modal</td>
  286. <td>This event is fired immediately when the <code>hide</code> instance method has been called.</td>
  287. </tr>
  288. <tr>
  289. <td>hidden.bs.modal</td>
  290. <td>This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).</td>
  291. </tr>
  292. <tr>
  293. <td>loaded.bs.modal</td>
  294. <td>This event is fired when the modal has loaded content using the <code>remote</code> option.</td>
  295. </tr>
  296. </tbody>
  297. </table>
  298. </div><!-- /.table-responsive -->
  299. {% highlight js %}
  300. $('#myModal').on('hidden.bs.modal', function (e) {
  301. // do something...
  302. })
  303. {% endhighlight %}
  304. </div>