Destroy multiple sliders at once

2

I want to destroy all my sliders when the page hits the size of 768px. For this I made this code below:

if($(window).width() >= 768){
    $(".owl-carousel-linhas").data('owlCarousel').destroy();
}

I have several sliders on my page like this:

<div class="owl-carousel-linhas">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
</div>

<div class="owl-carousel-linhas">
   <div class="item"></div>
   <div class="item"></div>
</div>

<div class="owl-carousel-linhas">
   <div class="item"></div>
   <div class="item"></div>
   <div class="item"></div>
   <div class="item"></div>
</div>

And the code I made above only destroys the first slider, the rest does not.

    
asked by anonymous 16.06.2015 / 16:32

2 answers

1

I managed to resolve. It was simple, until.

$(".owl-carousel-linhas").each(function (index, obj){
    $(this).data('owlCarousel').destroy();
});

I changed the obj to $(this) .

    
16.06.2015 / 16:51
1

Based on your comment, I'm going to make a change that might solve your problem by putting this code inside your if :

while($(".owl-carousel-linhas").length > 0){
    $($(".owl-carousel-linhas")[0]).data('owlCarousel').destroy();
}

Make sure this solves your problem.

    
16.06.2015 / 16:39