10carousel.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Blasting off with Bootstrap</title>
  5. <meta charset="utf-8"/>
  6. <meta http-equiv="X-UA-COMPATIBLE" content="IE=Edge"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <link rel="stylesheet" href="../css/bootstrap.min.css"/>
  9. <!--[if lt IE 9]>
  10. <script src="../js/html5shiv.3-7-0.js"></script>
  11. <script src="../js/respond.1-4-2.min.js"></script>
  12. <![endif]-->
  13. <style type="text/css">
  14. img {
  15. width: 100%;
  16. height: 50vh !important;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="container">
  22. <div id="bestCarsCarousel" class="carousel slide" data-ride="carousel">
  23. <!-- Indicators -->
  24. <ol class="carousel-indicators">
  25. <li data-target="#bestCarsCarousel" data-slide-to="0" class="active"></li>
  26. <li data-target="#bestCarsCarousel" data-slide-to="1"></li>
  27. <li data-target="#bestCarsCarousel" data-slide-to="2"></li>
  28. </ol>
  29. <!-- Wrapper for slides -->
  30. <div class="carousel-inner">
  31. <div class="item active">
  32. <img src="images/car1.jpg" />
  33. <div class="carousel-caption">
  34. <h3>Concept-car Alfa-Romeo</h3>
  35. <p>Lorem ipsum dolor sic amet, consectetur ...</p>
  36. </div>
  37. </div>
  38. <div class="item">
  39. <img src="images/car2.jpg"/>
  40. <div class="carousel-caption">
  41. <h3>Concept-car Honda</h3>
  42. <p>Lorem ipsum dolor sic amet, consectetur ...</p>
  43. </div>
  44. </div>
  45. <div class="item">
  46. <img src="images/car3.jpg" />
  47. <div class="carousel-caption">
  48. <h3>Concept-car Chrysler BMW</h3>
  49. <p>Loorem ipsum dolor sic amet, consectetur ...</p>
  50. </div>
  51. </div>
  52. <!-- Controls -->
  53. <a href="#bestCarsCarousel" class="left carousel-control" data-slide="prev">
  54. <span class="glyphicon glyphicon-chevron-left"></span>
  55. </a>
  56. <a href="#bestCarsCarousel" class="right carousel-control" data-slide="next">
  57. <span class="glyphicon glyphicon-chevron-right"></span>
  58. </a>
  59. </div>
  60. </div>
  61. </div>
  62. <!-- https://ajax.googleapis.com/ajax/libs/jquery/1.11.1.jquery.min.js -->
  63. <script src="../js/jquery-1.11.2.min.js"></script>
  64. <script src="../js/bootstrap.js"></script>
  65. <script type="text/javascript">
  66. var options = {
  67. interval: 1000,
  68. // Stop sliding on hover. Default: no
  69. pause: "hover",
  70. // Continue to first after last
  71. wrap: false
  72. }
  73. function getImage(j) {
  74. var ret;
  75. ret = $(j).find('.item.active').children('img')[0].getAttribute('src');
  76. return ret;
  77. }
  78. /* Or carousel(command) where command in:
  79. - cycle : enable cycling
  80. - pause cycling
  81. - <number> time duration between slides
  82. - prev change to previous slide
  83. - next change to next slide
  84. */
  85. $('#bestCarsCarousel').carousel(options);
  86. $('#bestCarsCarousel').on('slide.bs.carousel', function() {
  87. console.log("Sliding out", getImage(this));
  88. });
  89. $('#bestCarsCarousel').on('slid.bs.carousel', function() {
  90. var src = getImage(this);
  91. console.log("Slid in", getImage(this));
  92. });
  93. </script>
  94. </body>
  95. </html>