Question

Hi all am using bootstrap carousel my problem is i need to add show previous control only after clicking the first slide and if the slide ends has to disable the next control.! sample image

how do i get this.

my caurosel looks like

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    ...
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>
</div>
Was it helpful?

Solution

You could conditionally show the controls by determining the current slide like this..

$('#myCarousel').on('slid.bs.carousel', function (ev) {
  var carouselData = $(this).data('bs.carousel');
  var currentIndex = carouselData.getActiveIndex();

  if (currentIndex >= 1) {
    $('.left').show();
  }
  else {
    $('.left').hide();
  }

  if (currentIndex === (carouselData.$items.length-1)) {
    $('.right').hide();
    $('.left').show();
  }
  else {
    $('.right').show();
  }
})

Demo: http://www.bootply.com/R11GWNqkSh

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top