You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 line
3.2 KiB

  1. <div class="bs-docs-section">
  2. <h1 id="alerts" class="page-header">Alert messages <small>alert.js</small></h1>
  3. <h2 id="alerts-examples">Example alerts</h2>
  4. <p>Add dismiss functionality to all alert messages with this plugin.</p>
  5. <p>When using a <code>.close</code> button, it must be the first child of the <code>.alert-dismissible</code> and no text content may come before it in the markup.</p>
  6. <div class="bs-example bs-example-standalone">
  7. <div class="alert alert-warning alert-dismissible fade in" role="alert">
  8. <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  9. <strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
  10. </div>
  11. <div class="alert alert-danger alert-dismissible fade in" role="alert">
  12. <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  13. <h4>Oh snap! You got an error!</h4>
  14. <p>Change this and that and try again. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum.</p>
  15. <p>
  16. <button type="button" class="btn btn-danger">Take this action</button>
  17. <button type="button" class="btn btn-default">Or do this</button>
  18. </p>
  19. </div>
  20. </div><!-- /example -->
  21. <h2 id="alerts-usage">Usage</h2>
  22. <p>Just add <code>data-dismiss="alert"</code> to your close button to automatically give an alert close functionality. Closing an alert removes it from the DOM.</p>
  23. {% highlight html %}
  24. <button type="button" class="close" data-dismiss="alert">
  25. <span aria-hidden="true">&times;</span>
  26. <span class="sr-only">Close</span>
  27. </button>
  28. {% endhighlight %}
  29. <p>To have your alerts use animation when closing, make sure they have the <code>.fade</code> and <code>.in</code> classes already applied to them.</p>
  30. <h3>Methods</h3>
  31. <h4>$().alert()</h4>
  32. <p>Makes an alert listen for click events on descendant elements which have the <code>data-dismiss="alert"</code> attribute. (Not necessary when using the data-api's auto-initialization.)</p>
  33. <h4>$().alert('close')</h4>
  34. <p>Closes an alert by removing it from the DOM. If the <code>.fade</code> and <code>.in</code> classes are present on the element, the alert will fade out before it is removed.</p>
  35. <h3>Events</h3>
  36. <p>Bootstrap's alert plugin exposes a few events for hooking into alert functionality.</p>
  37. <div class="table-responsive">
  38. <table class="table table-bordered table-striped">
  39. <thead>
  40. <tr>
  41. <th style="width: 150px;">Event Type</th>
  42. <th>Description</th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. <tr>
  47. <td>close.bs.alert</td>
  48. <td>This event fires immediately when the <code>close</code> instance method is called.</td>
  49. </tr>
  50. <tr>
  51. <td>closed.bs.alert</td>
  52. <td>This event is fired when the alert has been closed (will wait for CSS transitions to complete).</td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div><!-- /.table-responsive -->
  57. {% highlight js %}
  58. $('#myAlert').on('closed.bs.alert', function () {
  59. // do something…
  60. })
  61. {% endhighlight %}
  62. </div>