Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Losing setTimeout value after I switch tabs

I have several columns of logos and I want to run a function that animates the logos on each column but not at the same time, I want to have a delay between the time the function runs for each column. Here is my code:

var startRotation = function() {
  $( ".ticker" ).each( function( index, element ){
    myInterval = setTimeout(function() { 
      otherInterval = setInterval(function(){ 
        slideImageUp(element); //runs function to animate
      }, 3000);
    }, 1000 * index); 
  });
};

The problem is setTimeout resets after I switch tabs on the browser and eventually the columns all animate at the same time. I've also tried pretty much every solution I found here and can't seem to figure out a way to make it work. I've been working on it for a while and I think the solution might be simple but I just can't see it. Thanks.

https://jsfiddle.net/dae0L0qu/3/

like image 275
gazelle Avatar asked Feb 16 '26 11:02

gazelle


1 Answers

Just do it the other way. Each 3 seconds, set timeouts for all the logos at the appropriate times.

var startRotation = function() {
  otherInterval = setInterval(function(){ 
      $( ".ticker" ).each( function( index, element ){
        myInterval = setTimeout(function() { 
          slideImageUp(element); //runs function to animate
        }, 1000 * index); 
      });
  }, 3000);
};
like image 67
Kamyar Infinity Avatar answered Feb 17 '26 23:02

Kamyar Infinity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!