Bootstrap Carousel



Bootstrap Carousel

Bootstrap Carousel

Bootstrap Carousel是一种灵活的响应式方法,用于向网页添加滑块。它具有足够的响应能力和灵活性,足以允许您添加图像,iframe,视频或您要添加的任何其他类型的内容。
Carousel插件:
Carousel插件是一个用于在元素之间循环的组件,例如Carousel。如果要单独添加插件功能,则必须一次或全部使用carousel.js文件(使用" bootstrap.js"或" bootstrap.min.js")。

启动Carousel示例

让我们以Carousel示例为例,了解如何创建基本的Carousel。
<!DOCTYPE html>
<html lang="en">
  <head>
     <title>Bootstrap Carousel</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
  </head>
<style>
  .carousel-inner > .item > img,
  .carousel-inner > .item > a > img {
      width: 80%;
      margin: auto;
  }
</style>
  <body>
<div class="container">
  <h1>Carousel Example</h1>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!--Indicators-->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <!--Wrapper for slides-->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="images/jokes1.jpg" alt="jokes 1" >
      </div>
      <div class="item">
        <img src="images/jokes2.jpg" alt="jokes 2" >
      </div>
    
      <div class="item">
        <img src="images/jokes3.jpg" alt="jokes 3" >
      </div>
    </div>
    <!--Left and right controls-->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
</div><!--corousel end-->
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  </body>
</html>


Bootstrap Carousel示例: 向幻灯片添加字幕

如果要将字幕添加到幻灯片,则必须添加<div class="carousel-caption">
<!DOCTYPE html>
<html lang="en">
  <head>
     <title>Job</title>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
  </head>
<style>
  .carousel-inner > .item > img,
  .carousel-inner > .item > a > img {
      width: 80%;
      margin: auto;
  }
</style>
<body>
<div class="container">
  <h1>Carousel Example</h1>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!--Indicators-->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <!--Wrapper for slides-->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="images/jokes1.jpg" alt="jokes 1" >
        <h3>Santa-Banta</h3>
        <p>Read Santa-Banta jokes at lidihuo.</p>
      </div>
      <div class="item">
        <img src="images/jokes2.jpg" alt="jokes 2" >
         <h3>Santa-Banta</h3>
        <p>Read Santa-Banta jokes at lidihuo.</p>
      </div>
    
      <div class="item">
        <img src="images/jokes3.jpg" alt="jokes 3" >
         <h3>Santa-Banta</h3>
        <p>Read Santa-Banta jokes at lidihuo.</p>
      </div>
    </div>
    <!--Left and right controls-->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
</div><!--corousel end-->
</div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  </body>
</html>