Bootstrap:Carousel不工作

时间:2017-04-21 16:41:04

标签: javascript html css twitter-bootstrap

尝试在我正在创建的网页中设置轮播。旋转木马应包含3张图像,但图像只是一个堆叠在另一个上面。此索引文件位于同时包含css,fonts和js文件夹的文件夹中。我不确定这是否是一个微不足道的修复,但我无法弄明白。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head 
      content must come *after* these tags -->
  <title>Bootstrap 101 Template</title>

  <!-- Bootstrap -->
  <link href="css/bootstrap.css" rel="stylesheet">

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media 
      queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js">
        </script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js">
        </script>
      <![endif]-->
</head>

<body>
  <div id="carouselControls" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner" role="listbox">
      <div class="carousel-item active">
        <a href="#">
          <img class="d-block img-fluid" src="https://fgl.scene7.com/is/image/FGLSportsLtd/332266454_99_a
                ? wid=288&hei=288&op_sharpen=1&resMode=sharp2" alt="First 
                slide">
        </a>
      </div>
      <div class="carousel-item">
        <a href="#">
          <img class="d-block img-fluid" src="https://fgl.scene7.com/is/image/FGLSportsLtd/332266454_99_a
                ? wid=288&hei=288&op_sharpen=1&resMode=sharp2" alt="Second 
                slide">
        </a>
      </div>
      <div class="carousel-item">
        <a href="#">
          <img class="d-block img-fluid" src="https://fgl.scene7.com/is/image/FGLSportsLtd/332266454_99_a 
                ? wid=288&hei=288&op_sharpen=1&resMode=sharp2" alt="Third 
                slide">
        </a>
      </div>
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselControls" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hiddin="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="carouselControls" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
  </div>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

  <!-- Include all compiled plugins (below), or include individual files as 
      needed -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>

</html>

在JSFiddle上:https://jsfiddle.net/057z6f35/1/

1 个答案:

答案 0 :(得分:2)

该问题与您拥有的引导程序版本有关。我怀疑你使用的是bootstrap 3.x.在这种情况下,轮播内部物品需要具有一类&#34;项目&#34;不是&#34; carousel-item&#34;。 carousel-item类适用于v4 alpha版本。将代码更新为:

    <div class="carousel-inner" role="listbox">
        <div class="item active">
            <a href="#">
            <img class="d-block img-fluid" 
            src="https://fgl.scene7.com/is/image/FGLSportsLtd/332266454_99_a
            ? wid=288&hei=288&op_sharpen=1&resMode=sharp2" alt="First 
            slide">
            </a>
        </div>
        <div class="item">
            <a href="#">
            <img class="d-block img-fluid" 
            src="https://fgl.scene7.com/is/image/FGLSportsLtd/332266454_99_a
            ? wid=288&hei=288&op_sharpen=1&resMode=sharp2" alt="Second 
            slide">
            </a>
        </div>
        <div class="item">
            <a href="#">
            <img class="d-block img-fluid" 
            src="https://fgl.scene7.com/is/image/FGLSportsLtd/332266454_99_a 
            ? wid=288&hei=288&op_sharpen=1&resMode=sharp2" alt="Third 
            slide">
            </a>
        </div>
    </div>