setTimeout speeds up with multiple tabs

后端 未结 7 1609
慢半拍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 08:09

    From the jQuery documentation:

    Because of the nature of requestAnimationFrame(), you should never queue animations using a setInterval or setTimeout loop. In order to preserve CPU resources, browsers that support requestAnimationFrame will not update animations when the window/tab is not displayed. If you continue to queue animations via setInterval or setTimeout while animation is paused, all of the queued animations will begin playing when the window/tab regains focus. To avoid this potential problem, use the callback of your last animation in the loop, or append a function to the elements .queue() to set the timeout to start the next animation.

提交回复
热议问题