0

I am using two sliders, the issue is on the second one. It should show multiple images at once then slide one item at a time. But in this situation, it only shows on item. I tried to follow all the steps on this thread but it still doesn't work: Bootstrap: Slide only one image among the multiple images in an item of the carousel

$('#myCarousel').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));
  }
});
.carousel-inner .active.left {
  left: -25%;
}

.carousel-inner .active.right {
  left: 25%;
}

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

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

.carousel-control {
  width: 4%;
}

.carousel-control.left,
.carousel-control.right {
  margin-left: 15px;
  background-image: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="container-fluid">
  <div class="col-sm-12 margin-top-20">
    <div id="largeCarousel" class="carousel slide" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#largeCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#largeCarousel" data-slide-to="1"></li>
        <li data-target="#largeCarousel" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner custom_carousel_holder">
        <div class="item active">
          <img class="img-responsive center-block" src="/attigo2/public/images/hi-res barbatos.jpg" alt="Barbie" />
          <div class="carousel-caption">
            <h3>Los Angeles</h3>
            <p>LA is always so much fun!</p>
          </div>
        </div>
        <div class="item">
          <img class="img-responsive center-block" src="/attigo2/public/images/hi-res barbatos.jpg" alt="Barbie" />
          <div class="carousel-caption">
            <h3>Chicago</h3>
            <p>Thank you, Chicago!</p>
          </div>
        </div>

        <div class="item">
          <img class="img-responsive center-block" src="/attigo2/public/images/hi-res barbatos.jpg" alt="Barbie" />
          <div class="carousel-caption">
            <h3>New York</h3>
            <p>We love the Big Apple!</p>
          </div>
        </div>
      </div>
      <a class="left carousel-control" href="#largeCarousel" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#largeCarousel" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
  </div>
  <div class="col-sm-12 text-center margin-top-20">
    <h3>Discover Our Brands</h3>
  </div>

  <div class="col-md-12 text-center">
    <h3>Bootstrap 3 Multiple Slide Carousel</h3>
  </div>
  <div class="col-md-6 col-md-offset-3">
    <div class="carousel slide" id="myCarousel">
      <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="#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>
</div>

I already checked out the samples on the provided link above and copy pasted the heck out of it and it still doesn't work. I'm not really sure if i'm causing a conflict on both sliders.

Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21
Claude
  • 11
  • 1
  • 6

1 Answers1

0

Here is The solution your code wise all correct i think you forget to add bootstrap js file here the working fiddle with cdn

https://jsfiddle.net/hahkarthick/7n8aux8k/

$('#myCarousel').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));
    }
});
.carousel-inner .active.left { left: -25%; }
.carousel-inner .active.right{ left:  25%; }
.carousel-inner .next        { left:  25%; }
.carousel-inner .prev        { left: -25%; }
.carousel-control            { width:  4%; }
.carousel-control.left,.carousel-control.right {margin-left:15px;background-image:none;}
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <div class="container-fluid">
    <div class="col-sm-12 margin-top-20">
        <div id="largeCarousel" class="carousel slide" data-ride="carousel">
            <ol class="carousel-indicators">
                <li data-target="#largeCarousel" data-slide-to="0" class="active"></li>
                <li data-target="#largeCarousel" data-slide-to="1"></li>
                <li data-target="#largeCarousel" data-slide-to="2"></li>
            </ol>
            <div class="carousel-inner custom_carousel_holder">
                <div class="item active">
                    <img class="img-responsive center-block" src="/attigo2/public/images/hi-res barbatos.jpg" alt="Barbie"/>
                    <div class="carousel-caption">
                        <h3>Los Angeles</h3>
                        <p>LA is always so much fun!</p>
                    </div>
                </div>
                <div class="item">
                    <img class="img-responsive center-block" src="/attigo2/public/images/hi-res barbatos.jpg" alt="Barbie"/>
                    <div class="carousel-caption">
                        <h3>Chicago</h3>
                        <p>Thank you, Chicago!</p>
                    </div>
                </div>

                <div class="item">
                    <img class="img-responsive center-block" src="/attigo2/public/images/hi-res barbatos.jpg" alt="Barbie"/>
                    <div class="carousel-caption">
                        <h3>New York</h3>
                        <p>We love the Big Apple!</p>
                    </div>
                </div>
            </div>
            <a class="left carousel-control" href="#largeCarousel" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#largeCarousel" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>
    </div>
    <div class="col-sm-12 text-center margin-top-20">
        <h3>Discover Our Brands</h3>
    </div>

    <div class="col-md-12 text-center"><h3>Bootstrap 3 Multiple Slide Carousel</h3></div>
    <div class="col-md-6 col-md-offset-3">
        <div class="carousel slide" id="myCarousel">
            <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="#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>
Harish Karthick
  • 710
  • 2
  • 12
  • 26
  • thanks Harish,I already have the js cdn's, I placed it after the

    tag though. oddly enough when i moved it inside the

    tag it worked but not as I expect it to be. it slides 4 images at the same time. i need to have it show 4 to 8 images while sliding in a single image in, and another out and i'm not really sure how to do it. i have a hunch that i need to do something with the javascript but i'm not well versed.

    – Claude Aug 31 '17 at 10:01
  • @Genobee ok if u find this ans help make this as useful it will help for others – Harish Karthick Aug 31 '17 at 14:06
  • @Genobee Do you need single image in slide or slide 4 images to slide at once – Harish Karthick Aug 31 '17 at 14:07
  • yes, it's working now but it looks like its changing a bunch of slides due to the animation, but in reality it only shifts one slide at a time. – Claude Sep 06 '17 at 07:31
  • is there any way to change the animation? by the way, thanks for helping out – Claude Sep 07 '17 at 03:15
  • @Genobee in what way you need to animate – Harish Karthick Sep 07 '17 at 04:09
  • a simple one item per slide kind of thing, for example: <-1 2 3 4 5 6-> to <- 2 3 4 5 6 1-> per interval – Claude Sep 07 '17 at 06:26
  • Change the class col-xs-3 -> col-xs-2 or what ever you need this will maintain how many images need in slide in carsole if u put col-xs-4 u will get 4 images its based on 12-grid system in bootstrap – Harish Karthick Sep 07 '17 at 08:51