Christina
Christina

Reputation: 34652

setInterval(function() and updateVars() for many carousels

Currently I have the following in my $(document).ready(function() AFTER the initialization for the sliders themselves.

This code represents 3 sliders and it works, but I have more sliders.

Is there a way to add a bunch of sliders here?

 setInterval(function(){

   var owldataTS = $(".testimonial-slider").data('owlCarousel');
   owldataTS.updateVars();

   var owldataMS = $(".multi-slider").data('owlCarousel');
   owldataMS.updateVars();

   var owldataMM = $(".mini-multi").data('owlCarousel');
   owldataMM.updateVars();


},1500);

BTW: this is used for when a page size changes without a re-size of the viewport, like toggling a sidebar or tab content.

Upvotes: 1

Views: 971

Answers (1)

T J
T J

Reputation: 43166

You can give a common class for the sliders and do:

setInterval(function(){
 $(".common-class").each(function(){
    $(this).data('owlCarousel').updateVars();
 });
},1500);

Upvotes: 3

Related Questions