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.
 
 
 
 

250 lines
10 KiB

  1. <div class="bs-docs-section">
  2. <h1 id="carousel" class="page-header">Carousel <small>carousel.js</small></h1>
  3. <p>A slideshow component for cycling through elemnts, like a carousel. <strong>Nested carousels are not supported.</strong></p>
  4. <h2 id="carousel-examples">Examples</h2>
  5. <div class="bs-example">
  6. <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  7. <ol class="carousel-indicators">
  8. <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
  9. <li data-target="#carousel-example-generic" data-slide-to="1"></li>
  10. <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  11. </ol>
  12. <div class="carousel-inner" role="listbox">
  13. <div class="item active">
  14. <img data-src="holder.js/900x500/auto/#777:#555/text:First slide" alt="First slide">
  15. </div>
  16. <div class="item">
  17. <img data-src="holder.js/900x500/auto/#666:#444/text:Second slide" alt="Second slide">
  18. </div>
  19. <div class="item">
  20. <img data-src="holder.js/900x500/auto/#555:#333/text:Third slide" alt="Third slide">
  21. </div>
  22. </div>
  23. <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
  24. <span class="glyphicon glyphicon-chevron-left"></span>
  25. <span class="sr-only">Previous</span>
  26. </a>
  27. <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
  28. <span class="glyphicon glyphicon-chevron-right"></span>
  29. <span class="sr-only">Next</span>
  30. </a>
  31. </div>
  32. </div><!-- /example -->
  33. {% highlight html %}
  34. <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  35. <!-- Indicators -->
  36. <ol class="carousel-indicators">
  37. <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
  38. <li data-target="#carousel-example-generic" data-slide-to="1"></li>
  39. <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  40. </ol>
  41. <!-- Wrapper for slides -->
  42. <div class="carousel-inner" role="listbox">
  43. <div class="item active">
  44. <img src="..." alt="...">
  45. <div class="carousel-caption">
  46. ...
  47. </div>
  48. </div>
  49. <div class="item">
  50. <img src="..." alt="...">
  51. <div class="carousel-caption">
  52. ...
  53. </div>
  54. </div>
  55. ...
  56. </div>
  57. <!-- Controls -->
  58. <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
  59. <span class="glyphicon glyphicon-chevron-left"></span>
  60. <span class="sr-only">Previous</span>
  61. </a>
  62. <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
  63. <span class="glyphicon glyphicon-chevron-right"></span>
  64. <span class="sr-only">Next</span>
  65. </a>
  66. </div>
  67. {% endhighlight %}
  68. <div class="bs-callout bs-callout-warning" id="callout-carousel-transitions">
  69. <h4>Transition animations not supported in Internet Explorer 8 &amp; 9</h4>
  70. <p>Bootstrap exclusively uses CSS3 for its animations, but Internet Explorer 8 &amp; 9 don't support the necessary CSS properties. Thus, there are no slide transition animations when using these browsers. We have intentionally decided not to include jQuery-based fallbacks for the transitions.</p>
  71. </div>
  72. <h3>Optional captions</h3>
  73. <p>Add captions to your slides easily with the <code>.carousel-caption</code> element within any <code>.item</code>. Place just about any optional HTML within there and it will be automatically aligned and formatted.</p>
  74. <div class="bs-example">
  75. <div id="carousel-example-captions" class="carousel slide" data-ride="carousel">
  76. <ol class="carousel-indicators">
  77. <li data-target="#carousel-example-captions" data-slide-to="0" class="active"></li>
  78. <li data-target="#carousel-example-captions" data-slide-to="1"></li>
  79. <li data-target="#carousel-example-captions" data-slide-to="2"></li>
  80. </ol>
  81. <div class="carousel-inner" role="listbox">
  82. <div class="item active">
  83. <img data-src="holder.js/900x500/auto/#777:#777" alt="First slide image">
  84. <div class="carousel-caption">
  85. <h3>First slide label</h3>
  86. <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
  87. </div>
  88. </div>
  89. <div class="item">
  90. <img data-src="holder.js/900x500/auto/#666:#666" alt="Second slide image">
  91. <div class="carousel-caption">
  92. <h3>Second slide label</h3>
  93. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  94. </div>
  95. </div>
  96. <div class="item">
  97. <img data-src="holder.js/900x500/auto/#555:#5555" alt="Third slide image">
  98. <div class="carousel-caption">
  99. <h3>Third slide label</h3>
  100. <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
  101. </div>
  102. </div>
  103. </div>
  104. <a class="left carousel-control" href="#carousel-example-captions" role="button" data-slide="prev">
  105. <span class="glyphicon glyphicon-chevron-left"></span>
  106. <span class="sr-only">Previous</span>
  107. </a>
  108. <a class="right carousel-control" href="#carousel-example-captions" role="button" data-slide="next">
  109. <span class="glyphicon glyphicon-chevron-right"></span>
  110. <span class="sr-only">Next</span>
  111. </a>
  112. </div>
  113. </div><!-- /example -->
  114. {% highlight html %}
  115. <div class="item">
  116. <img src="..." alt="...">
  117. <div class="carousel-caption">
  118. <h3>...</h3>
  119. <p>...</p>
  120. </div>
  121. </div>
  122. {% endhighlight %}
  123. <div class="bs-callout bs-callout-danger">
  124. <h4>Accessibility issue</h4>
  125. <p>The carousel component is generally not compliant with accessibility standards. If you need to be compliant, please consider other options for presenting your content.</p>
  126. </div>
  127. <h2 id="carousel-usage">Usage</h2>
  128. <h3>Multiple carousels</h3>
  129. <p>Carousels require the use of an <code>id</code> on the outermost container (the <code>.carousel</code>) for carousel controls to function properly. When adding multiple carousels, or when changing a carousel's <code>id</code>, be sure to update the relevant controls.</p>
  130. <h3>Via data attributes</h3>
  131. <p>Use data attributes to easily control the position of the carousel. <code>data-slide</code> accepts the keywords <code>prev</code> or <code>next</code>, which alters the slide position relative to its current position. Alternatively, use <code>data-slide-to</code> to pass a raw slide index to the carousel <code>data-slide-to="2"</code>, which shifts the slide position to a particular index beginning with <code>0</code>.</p>
  132. <p>The <code>data-ride="carousel"</code> attribute is used to mark a carousel as animating starting at page load. <strong class="text-danger">It cannot be used in combination with (redundant and unnecessary) explicit JavaScript initialization of the same carousel.</strong></p>
  133. <h3>Via JavaScript</h3>
  134. <p>Call carousel manually with:</p>
  135. {% highlight js %}
  136. $('.carousel').carousel()
  137. {% endhighlight %}
  138. <h3>Options</h3>
  139. <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-interval=""</code>.</p>
  140. <div class="table-responsive">
  141. <table class="table table-bordered table-striped">
  142. <thead>
  143. <tr>
  144. <th style="width: 100px;">Name</th>
  145. <th style="width: 50px;">type</th>
  146. <th style="width: 50px;">default</th>
  147. <th>description</th>
  148. </tr>
  149. </thead>
  150. <tbody>
  151. <tr>
  152. <td>interval</td>
  153. <td>number</td>
  154. <td>5000</td>
  155. <td>The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.</td>
  156. </tr>
  157. <tr>
  158. <td>pause</td>
  159. <td>string</td>
  160. <td>"hover"</td>
  161. <td>Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave.</td>
  162. </tr>
  163. <tr>
  164. <td>wrap</td>
  165. <td>boolean</td>
  166. <td>true</td>
  167. <td>Whether the carousel should cycle continuously or have hard stops.</td>
  168. </tr>
  169. <tr>
  170. <td>keyboard</td>
  171. <td>boolean</td>
  172. <td>true</td>
  173. <td>Whether the carousel should react to keyboard events.</td>
  174. </tr>
  175. </tbody>
  176. </table>
  177. </div><!-- /.table-responsive -->
  178. <h3>Methods</h3>
  179. <h4>.carousel(options)</h4>
  180. <p>Initializes the carousel with an optional options <code>object</code> and starts cycling through items.</p>
  181. {% highlight js %}
  182. $('.carousel').carousel({
  183. interval: 2000
  184. })
  185. {% endhighlight %}
  186. <h4>.carousel('cycle')</h4>
  187. <p>Cycles through the carousel items from left to right.</p>
  188. <h4>.carousel('pause')</h4>
  189. <p>Stops the carousel from cycling through items.</p>
  190. <h4>.carousel(number)</h4>
  191. <p>Cycles the carousel to a particular frame (0 based, similar to an array).</p>
  192. <h4>.carousel('prev')</h4>
  193. <p>Cycles to the previous item.</p>
  194. <h4>.carousel('next')</h4>
  195. <p>Cycles to the next item.</p>
  196. <h3>Events</h3>
  197. <p>Bootstrap's carousel class exposes two events for hooking into carousel functionality.</p>
  198. <p>Both events have the following additional properties:</p>
  199. <ul>
  200. <li><code>direction</code>: The direction in which the carousel is sliding (either <code>"left"</code> or <code>"right"</code>).</li>
  201. <li><code>relatedTarget</code>: The DOM element that is being slid into place as the active item.</li>
  202. </ul>
  203. <div class="table-responsive">
  204. <table class="table table-bordered table-striped">
  205. <thead>
  206. <tr>
  207. <th style="width: 150px;">Event Type</th>
  208. <th>Description</th>
  209. </tr>
  210. </thead>
  211. <tbody>
  212. <tr>
  213. <td>slide.bs.carousel</td>
  214. <td>This event fires immediately when the <code>slide</code> instance method is invoked.</td>
  215. </tr>
  216. <tr>
  217. <td>slid.bs.carousel</td>
  218. <td>This event is fired when the carousel has completed its slide transition.</td>
  219. </tr>
  220. </tbody>
  221. </table>
  222. </div><!-- /.table-responsive -->
  223. {% highlight js %}
  224. $('#myCarousel').on('slide.bs.carousel', function () {
  225. // do something…
  226. })
  227. {% endhighlight %}
  228. </div>