Search code examples
javascriptjquerynavigationhideowl-carousel-2

Owl Carousel 2 - hide custom nav (if 1 item)


I'm looking for a way to hide the Owl Carousel custom navigation, and to stop the "loop" functionality if there is only one item.

$('.owl-carousel').owlCarousel({
    loop: true,
    items: 1,
});

owl = $('.owl-carousel').owlCarousel();
$(".prev").click(function () {
    owl.trigger('prev.owl.carousel');
});
$(".next").click(function () {
    owl.trigger('next.owl.carousel');
});

Fiddle


Solution

  • You can first of all, use an if

    loop: $('.owl-carousel img').length > 1 ? true : false,
    

    This will measure the amount of imgs in the carousel, and disable the loop. We can also add an if to use the hide() function

    Fiddle