setTimeout speeds up with multiple tabs

后端 未结 7 1606
慢半拍i
慢半拍i 2020-12-10 07:47

I’m having a setTimeout problem similar to this one. But that solution doesn\'t help me since I can’t use php in my file.

My site has a slider with a list of images

7条回答
  •  抹茶落季
    2020-12-10 07:59

    I don't know if this will help you, but it helped me with my slideshow. What I did was everytime I called an animation that was supposed to happen at a set interval because of the setTimeout, I called clearQueue() which would get rid of any other animations that had been set to happen. then i'd call the animation. That way when you come back to that tab, you don't have all these animations queued up and it goes crazy. at max you'll only have one set up.

    So something like this:

           spotlight.timeOutSpotlight = setTimeout(function () {
                spotlight.clearQueue(); // get rid of other instances of the animation
                spotlight.animate(spotlight.i);
            }, 8000);
    

    It may not work in all cases (depending on timing), but I hope that helps somebody!

提交回复
热议问题