Owl Carousel, navigation disabled after reaching first/last item

owari picture owari · Sep 17, 2014 · Viewed 65.2k times · Source

I'm trying to use owl carousel for my website. I want to disable the navigation after it reach first/last item, for example by adding "disabled" class in navigation then disable it via css. Is it possible?

my code

http://jsfiddle.net/p3d52z4n/1/

Answer

Hovhannes Sargsyan picture Hovhannes Sargsyan · Jan 19, 2015

You can use callbak afterAction and with your custom controls

afterAction: function(){
  if ( this.itemsAmount > this.visibleItems.length ) {
    $('.next').show();
    $('.prev').show();

    $('.next').removeClass('disabled');
    $('.prev').removeClass('disabled');
    if ( this.currentItem == 0 ) {
      $('.prev').addClass('disabled');
    }
    if ( this.currentItem == this.maximumItem ) {
      $('.next').addClass('disabled');
    }

  } else {
    $('.next').hide();
    $('.prev').hide();
  }
}

Check the working demo - http://jsfiddle.net/p3d52z4n/9/