twitter bootstrap 3轮播中的图像数据-src

时间:2014-03-05 12:01:38

标签: javascript jquery html twitter-bootstrap

我正在尝试制作旋转木马。我刚刚复制并粘贴了示例网站上的代码和css。旋转木马工作正常但图像没有显示在滑块中。我尝试了相对和绝对的网址,但没有任何工作。控制台中没有出现任何错误。

我创建了一个jsfiddle: http://jsfiddle.net/52VtD/3327/

这是代码(减少以节省空间)

<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>
  <div class="carousel-inner">
    <div class="item active">
      <img data-src="https://imly.s3.amazonaws.com/bootstrap/img/car13.jpg" alt="First slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>Example headline.</h1>

        </div>
      </div>
    </div>
    <div class="item">
      <img data-src="https://imly.s3.amazonaws.com/bootstrap/img/car14.jpg" alt="Second slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>Another example headline.</h1>


        </div>
      </div>
    </div>
    <div class="item">
      <img data-src="https://imly.s3.amazonaws.com/bootstrap/img/car15.jpg" alt="Third slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>One more for good measure.</h1>


        </div>
      </div>
    </div>
  </div>
  <a class="left carousel-control" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
  <a class="right carousel-control" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div><!-- /.carousel -->

这是css:

.carousel {
  height: 350px;
  margin-bottom: 20px;
  margin-top:10px;
}
/* Since positioning the image, we need to help out the caption */
.carousel-caption {
  z-index: 10;
}

/* Declare heights because of positioning of img element */
.carousel .item {
  height: 350px;

}
.carousel-inner > .item > img {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  height: 350px;
}

谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:1)

使用普通<img src=""/>代码

使用<img src="https://imly.s3.amazonaws.com/bootstrap/img/car13.jpg" alt="First slide">

而不是

<img data-src="https://imly.s3.amazonaws.com/bootstrap/img/car13.jpg" alt="First slide">

<强> Updated FIDDLE