Ramish Hassan Riaz
Ramish Hassan Riaz

Reputation: 41

How to add condition for loop in owl carousel 2

I have this code everything is ok but I want to add condition on loop if the current product list has more then 6 product it should add loop otherwise make it false.

$(".demo .product-list").each(function() {
            var categoryCollectionList = $(this);

            categoryCollectionList.addClass("owl-carousel");
            categoryCollectionList.owlCarousel({
                nav: true,
                dots: false,
                margin: 0,
                autoplay: false,
                autoplaySpeed: 3000,
                autoWidth: true,
                stagePadding: 30,
            });

            var categoryCollectionListItem = categoryCollectionList.find('.owl-item').length > 6; // Check if the number of items is greater than 6

            // Set options dynamically
            categoryCollectionList.trigger('refresh.owl.carousel', [categoryCollectionListItem ? { loop: true, touchDrag: true, mouseDrag: true } : { loop: false, touchDrag: false, mouseDrag: false }]);
        });

I tried everything but not able to solve this issue...

I want to add condition on loop in owl-carousel. This is all I want

Upvotes: 1

Views: 83

Answers (0)

Related Questions