Answers for "setInterval issue, if i turn on new tap, that can be slower"

0

setInterval issue, if i turn on new tap, that can be slower

var rollImg = ["https://media.istockphoto.com/photos/fire-letter-a-of-burning-flame-picture-id844027508?k=6&m=844027508&s=170667a&w=0&h=dt0qXfyejRq_kjs5PqXcMf7Fij_opW7w1kfhfmH6dyQ=",
"https://cdn.leroymerlin.com.br/products/letra_b_11cm_acrilico_preto_kami_acrilicos_89622526_0001_600x600.jpg"];

var layer1Interval = 4000;
var layer2Interval = 5000;
var animationInterval = 1000;
$(function() {
  var roll = 1;
  function rollFnc () {
    setTimeout(function() {
      roll++;
      if (roll > 2) {
        roll = 1;
      }
      $("#box1").attr("src", rollImg[roll - 1]);
      setTimeout(rollFnc, layer1Interval + animationInterval * 1.5);
    }, animationInterval / 2);
  }
  
  rollFnc();
})

var tl = new TimelineMax({
  repeat: -1,
  repeatDelay: (layer1Interval / 1000)
});
tl.from(".layer1", animationInterval / 1000, {
  scaleX: 0,
  transformOrigin: "left",
  ease: 'expo.inOut'
});
tl.to(".layer1", animationInterval / 1000, {
  scaleX: 0,
  transformOrigin: "right",
  ease: 'expo.out'
});
Posted by: Guest on June-26-2021

Code answers related to "setInterval issue, if i turn on new tap, that can be slower"

Code answers related to "Javascript"

Browse Popular Code Answers by Language