Disabling Owl Carousel at a specific viewport width

前端 未结 5 1307
说谎
说谎 2021-02-19 17:38

I\'m currently using Owl Carousel to show a gallery on desktop/laptop sized devices. However on smaller devices I\'d like to disable the plugin and show each image stacked under

5条回答
  •  悲&欢浪女
    2021-02-19 18:15

    mcmimik's answer is correct, but I had to make one change for it to work for me.

    In the function:

        $(window).resize(function () {
        if ($(window).width() < 641) {
            if ($('.owl-carousel').hasClass('off')) {
                var owlActive = owl.owlCarousel(owlOptions);
                owl.removeClass('off');
            }
        } else {
            if (!$('.owl-carousel').hasClass('off')) {
                 owl.addClass('off').trigger('destroy.owl.carousel');
                owl.find('.owl-stage-outer').children(':eq(0)').unwrap();
            }
        }
    });
    

    Swap outowl.addClass('off').trigger('destroy.owl.carousel'); for owl.addClass('off').data("owlCarousel").destroy();:

        $(window).resize(function () {
        if ($(window).width() < 641) {
            if ($('.owl-carousel').hasClass('off')) {
                var owlActive = owl.owlCarousel(owlOptions);
                owl.removeClass('off');
            }
        } else {
            if (!$('.owl-carousel').hasClass('off')) {
                owl.addClass('off').data("owlCarousel").destroy();
                owl.find('.owl-stage-outer').children(':eq(0)').unwrap();
            }
        }
    });
    

提交回复
热议问题