Boostrap旋转木马每个项目移动版3列

时间:2017-02-21 00:42:06

标签: jquery html css twitter-bootstrap carousel

我正在试图做这个link中的内容。但我需要每个项目有3个div或元素。我的问题是,当处于移动模式时,每个项目的最后2个mi元素都被消除了。我已经阅读了这个post,但是在移动模式下我没有为每个项目提供3列。这是我的代码:

HTML:

 <div class="col-md-12 text-center"><h3>Product Carousel</h3></div>
    <div class="col-md-12 ">
    <div class="carousel slide" data-ride="carousel" data-type="multi" data-interval="3000" id="myCarousel">
      <div class="carousel-inner">
        <div class="item active">
          <div class="col-md-4 col-sm-6 col-xs-12"><a href="#"><img src="http://placehold.it/500/e499e4/fff&amp;text=1" class="img-responsive"></a></div>
          <div class="col-md-4 col-sm-6 col-xs-12"><a href="#"><img src="http://placehold.it/500/e499e4/fff&amp;text=1" class="img-responsive"></a></div>
          <div class="col-md-4 col-sm-6 col-xs-12"><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-md-4 col-sm-6 col-xs-12"><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-md-4 col-sm-6 col-xs-12"><a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=3" class="img-responsive"></a></div>
        </div>
        <div class="item">
          <div class="col-md-4 col-sm-6 col-xs-12"><a href="#"><img src="http://placehold.it/500/f4f4f4&amp;text=4" class="img-responsive"></a></div>
        </div>
        <div class="item">
          <div class="col-md-4 col-sm-6 col-xs-12"><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-md-4 col-sm-6 col-xs-12"><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-md-4 col-sm-6 col-xs-12"><a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=7" class="img-responsive"></a></div>
        </div>
        <div class="item">
          <div class="col-md-4 col-sm-6 col-xs-12"><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="#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-control            { width:  4%; }
.carousel-control.left,.carousel-control.right {margin-left:15px;background-image:none;}
@media (max-width: 767px) {
    .carousel-inner .active.left { left: -100%; }
    .carousel-inner .next        { left:  100%; }
    .carousel-inner .prev        { left: -100%; }
    .active > div { display:none; }
    .active > div:first-child { display:block; }

}
@media (min-width: 767px) and (max-width: 992px ) {
    .carousel-inner .active.left { left: -50%; }
    .carousel-inner .next        { left:  50%; }
    .carousel-inner .prev        { left: -50%; }
    .active > div { display:none; }
    .active > div:first-child { display:block; }
    .active > div:first-child + div { display:block; }
}
@media (min-width: 992px ) {
    .carousel-inner .active.left { left: -25%; }
    .carousel-inner .next        { left:  25%; }
    .carousel-inner .prev        { left: -25%; }    
}

JS:

$('.carousel[data-type="multi"] .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));
  }
});

提前致谢。

1 个答案:

答案 0 :(得分:-1)

我最终使用了slick.js。以自适应方式自定义比自举更灵活。