下面的代码一次滑动一个缩略图。我想一次滑动3。有人可以帮忙吗?谢谢!

$('.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));
  }
});

最佳答案

诀窍是使用引导类“row”。

jQuery的

$('#myCarousel').carousel({
  interval: 10000
})

html
<div class="col-md-7">
    <div id="myCarousel" class="carousel slide">
        <div class="carousel-inner">
            <div class="item active">
                <div class="row">
                    <div class="col-md-4">
                        <a href="#"><img src="http://placehold.it/500/bbbbbb/fff&amp;text=1" class="img-responsive"></a>
                    </div>
                    <div class="col-md-4">
                        <a href="#"><img src="http://placehold.it/500/CCCCCC&amp;text=2" class="img-responsive"></a>
                    </div>
                    <div class="col-md-4">
                        <a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=3" class="img-responsive"></a>
                    </div>
                </div>
            </div>
            <div class="item">
                <div class="row">
                    <div class="col-md-4">
                        <a href="#"><img src="http://placehold.it/500/f4f4f4&amp;text=4" class="img-responsive"></a>
                    </div>
                    <div class="col-md-4">
                        <a href="#"><img src="http://placehold.it/500/fcfcfc/333&amp;text=5" class="img-responsive"></a>
                    </div>
                    <div class="col-md-4">
                        <a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=6" class="img-responsive"></a>
                    </div>
                </div>
            </div>
        </div>
        <a class="left carousel-control" href="#myCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
    </div>
</div>

的CSS
.carousel-inner .active.left { left: -33%; }
.carousel-inner .next        { left:  33%; }
.carousel-inner .prev        { left: -33%; }
.carousel-control.left,.carousel-control.right {background-image:none; color: black;}

希望能帮助到你!

09-25 15:13