Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Owl Carousel, navigation disabled after reaching first/last item

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

$(document).ready(function() {
  var owl = $("#owl-demo");
  owl.owlCarousel({
    rewindNav : false,	
    pagination : false,        
    items : 4
  });
  // Custom Navigation Events
  $(".next").click(function(){
    owl.trigger('owl.next');
  })
  $(".prev").click(function(){
    owl.trigger('owl.prev');
  })
});
.item { background: #e5e5e5; margin: 10px}
.btn { background: #bd0000; color: #fff; padding: 5px 10px; cursor: pointer}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.js"></script>
<link href="http://owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.css" rel="stylesheet" />

<div id="owl-demo" class="owl-carousel owl-theme">
  <div class="item"><h1>1</h1></div>
  <div class="item"><h1>2</h1></div>
  <div class="item"><h1>3</h1></div>
  <div class="item"><h1>4</h1></div>
  <div class="item"><h1>5</h1></div>
  <div class="item"><h1>6</h1></div>
  <div class="item"><h1>7</h1></div>
  <div class="item"><h1>8</h1></div>
  <div class="item"><h1>9</h1></div>
  <div class="item"><h1>10</h1></div>
</div>

<div class="customNavigation">
  <a class="btn prev">Previous</a>
  <a class="btn next">Next</a>
</div>

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

like image 853
owari Avatar asked Sep 17 '14 15:09

owari


People also ask

How do I customize my owl carousel navigation?

Setting Up Owl Carousel 2 is easy; first place the jQuery, right after that, call the owl carousel JavaScript link. To provide the aesthetics also add the carousel CSS links. We are using the CDN links however you can download the owl carousel and call the scripts and CSS locally.

How do you turn off auto slide on owl carousel?

In order to stop owl auto play you can trigger the corresponding event: stop. owl.

How do I reinitialize my carousel owl?

You can initialize the carousel and store it in a variable and using that variable you can refresh the owl carousel. like the below example. var $owlCarousel = $('. owl-carousel').

How do you change transitions in owl carousel?

Use transitionStyle option to set transtion. There are four predefined transitions: "fade" , "backSlide" , goDown and scaleUp . You can also build your own transition styles easily. For example by adding "YourName" value transitionStyle: "YourName" , owlCarousel will add .


2 Answers

Simplest solution:

OwlCarousel 2 gives disabled class to nav elements when the first/last element is reached.

So you could just need something like that:

.owl-nav{
  .disabled{
    display: none;
  }
}
like image 73
Nottenga Avatar answered Sep 17 '22 11:09

Nottenga


I was searching to solution , i found some code and i combine them. Its works for me. when first item left arrow hiding when last item right arrow hiding.

Attention to .on() event

$('.homeSlider').owlCarousel({
    loop: false ,
    autoplay: false,
    navClass: ['fa fa-chevron-left', 'fa fa-chevron-right'],
    navText: ['', ''],
    margin: 20,
    startPosition: -0,
    items: 3,
    nav: true,
    dots: false,
    center: false,
    autoWidth: true,
    responsive: {
        0: {
            items: 1
        },
        600: {
            items:2,
            margin: 20,
            startPosition: 0,
            loop: true,
            autoWidth: true,
            center: false

        },
        992: {
            items: 3
        },
        1920: {
            items: 5
        }
    }}).on('initialized.owl.carousel changed.owl.carousel refreshed.owl.carousel', function (event) {
    //alert("s");
    if (!event.namespace) return;
    var carousel = event.relatedTarget,
        element = event.target,
        current = carousel.current();

    if(current === carousel.maximum()) $('.homeSlider .fa-chevron-right').hide();
    if(current === carousel.minimum()) $('.homeSlider .fa-chevron-left').hide();

});
$('.homeSlider .fa-chevron-left').hide();
like image 24
Ahmet Uğur Avatar answered Sep 18 '22 11:09

Ahmet Uğur