Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop bootstrap carousel to cycle at the end of the slide

I wanted such that when I press the next button on the carousel, if it has reached the end of the slide then don't wrap around and go back to the first slide. Is there an easy way to do this in bootstrap 3?

like image 286
adit Avatar asked Aug 29 '14 05:08

adit


1 Answers

Setting the wrap option to false makes the carousel to stop cycling automatically.

$('#myCarousel').carousel({
  interval: 1000,
  wrap: false
});

Also if you want to hide the left and right controls when the carousel is showing the first/last slides you can do this way:

  $('#myCarousel').on('slid.bs.carousel', '', function() {
  var $this = $(this);

  $this.children('.carousel-control').show();

  if($('.carousel-inner .item:first').hasClass('active')) {
    $this.children('.left.carousel-control').hide();
  } else if($('.carousel-inner .item:last').hasClass('active')) {
    $this.children('.right.carousel-control').hide();
  }

});

DEMO

like image 178
ɐsɹǝʌ ǝɔıʌ Avatar answered Oct 10 '22 19:10

ɐsɹǝʌ ǝɔıʌ