Disabling Owl Carousel at a specific viewport width

前端 未结 5 1336
说谎
说谎 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:11

    function owlInitialize() {
       if ($(window).width() < 1024) {
          $('#carousel').owlCarousel();
       }else{
          $('#carousel').owlCarousel('destroy');
       }
    }
    
    $(document).ready(function(e) {
       owlInitialize();
    });
    
    $(window).resize(function() {
       owlInitialize();
    });
    

    Working Fiddle: https://jsfiddle.net/j6qk4pq8/187/

提交回复
热议问题