Bootstrap carousal - 逐个显示多个幻灯片时出现的问题

时间:2018-01-30 06:30:12

标签: javascript jquery html css twitter-bootstrap

嗨,我正在研究bootstrap carousal。我试图在箭头单击上逐个显示多张幻灯片。我已经使用了一些代码和Somewhat它正在工作,但没有预料到。我想在点击时只移动一张图片。但是,这里整个图像幻灯片正在移动。请帮我在点击时只移动一张图片。提前谢谢。

$('#Carousel').carousel({
  interval: 4000
})
$('#Carousel .item').each(function() {
  var next = $(this).next();
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));

  for (var i = 0; i < 2; i++) {
    next = next.next();
    if (!next.length) {
      next = $(this).siblings(':first');
    }

    next.children(':first-child').clone().appendTo($(this));
  }
});
.dashboard-menu-wrapper {
  display: none
}

.carousel-inner .active.left {
  left: -10%;
}

.carousel-inner .next {
  left: 10%;
}

.carousel-inner .prev {
  left: -10%;
}

.carousel-control {
  width: 4%;
}

.carousel-control.left,
.carousel-control.right {
  background-image: none !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="col-md-12">
  <div class="carousel slide" id="Carousel">
    <div class="carousel-inner">
      <div class="item active">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/e499e4/fff&amp;text=1" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/e477e4/fff&amp;text=2" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=3" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/f4f4f4&amp;text=4" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/f566f5/333&amp;text=5" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=6" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=7" class="img-responsive"></a>
        </div>
      </div>
      <div class="item">
        <div class="col-xs-3">
          <a href="#"><img src="http://placehold.it/500/fcfcfc/333&amp;text=8" class="img-responsive"></a>
        </div>
      </div>
    </div>
    <a class="left carousel-control" href="#Carousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
    <a class="right carousel-control" href="#Carousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
  </div>
</div>

2 个答案:

答案 0 :(得分:0)

要获得所需的效果,您可以使用不同的轮播。我一直在尝试使用bootstrap做同样的事情,但无法达到结果。

OWL Carousel https://owlcarousel2.github.io使用对齐元素非常容易......

请参阅演示:https://owlcarousel2.github.io/OwlCarousel2/demos/basic.html

答案 1 :(得分:0)

试试这个。

$('#Carousel .item').each(function(){
  var next = $(this).next();
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));

  if (next.next().length>0) {
    next.next().children(':first-child').clone().appendTo($(this));
  } else {
    $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
  }
});  

- &GT; https://codepen.io/Not2Day2Die/pen/ddPbpE

希望这能帮到你