skip to Main Content

Hi I’m working on bootstrap carousal. I tried to show the multiple slide one by one on the arrow click. I have used some code and Somewhat it is working but not expected. I wanted to move only one image on click. But, here the whole image slide is moving. Please help me to move only one image on click. Thanks in advance.

$('#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

Answers


  1. To achieve the desired result you can use a different carousel. I`ve been trying a lot do the same with bootstrap but could not achieve the result.

    The OWL Carousel https://owlcarousel2.github.io work really easy with aligned elements…

    See demo: https://owlcarousel2.github.io/OwlCarousel2/demos/basic.html

    Login or Signup to reply.
  2. try this.

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

    -> https://codepen.io/Not2Day2Die/pen/ddPbpE

    Hope this help you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search