7

It seems if I'm scrolling the window, the window.setInterval doesn't get attached / fired while the scrolling is happening or after. Has anyone else seen the same issue?

I mean...

  • What could be causeing this?
  • What can I do to fix this?
2
  • Maybe it will stop all scripts when scrolling to save memory and make the animation goes faster. Just guessing. Oct 2, 2012 at 1:52
  • @Derek, no, everything else seems to execute fine, up to the point of the line right before setInterval.
    – Johnny
    Oct 2, 2012 at 1:54

4 Answers 4

9

iOS halts almost everything in response to user touch to guarantee it feels responsive. The setInterval issue is known, and there doesn't appear to be a workaround.

setInterval pauses in iphone/ipad (mobile Safari) during scrolling

EDIT

During the "freeze" the timer will not catch up once the user releases the screen. The missed events are not deferred, but lost entirely (a bug).

7
  • it does not just pause it, it doesn't fire even after the scrolling. The pausing issue is different, it happens if the setInterval is attached before the page scroll. In my case, it's attached during page scroll.
    – Johnny
    Oct 2, 2012 at 5:41
  • Right. During the "freeze" the timer will not catch up once the user releases the screen. But how does your event get attached during the scroll if the JS engine is paused during that time? Are you sure it's not just triggering during the scroll and getting discarded?
    – jimp
    Oct 2, 2012 at 6:08
  • I have the same problem. I am getting touch events if the user scrolls,lets go and then touches again. But my setTimeout are discarded. My ugly hacky solution is do a cleanup after each scroll event. (super ugly!)
    – Darwin
    Nov 5, 2012 at 21:58
  • This answer isn't correct. The timeout is never fired; it's silently discarded. It's a horrible, evil bug. Feb 10, 2013 at 19:27
  • @GlennMaynard Why is my answer incorrect? The OP asked if its known behavior (yes) and if there's a solution (no, at least not from Apple). Whether it's a bug or Apple just doesn't care, I'm not sure why it deserved a downvote.
    – jimp
    Feb 10, 2013 at 21:36
3

Found this (scary but amazing) workaround, and it's working for me in iOS 6.0:

https://gist.github.com/3755461

0

I'm not completely sure, but you could use a setTimeout instead of setInterval? It's generally bad practice to use setInterval anyway.

var delay = 100;
(function callee() {
    setTimeout(callee, delay);
})();
2
  • I'm not sure if I agree that using setInterval is generally a bad practice (it can definitely be overused though, especially for redrawing where requestAnimationFrame is better suited). However, an argument can be made for arguments.callee being a bad practice (which is why it's been removed from strict mode).
    – Strille
    Oct 2, 2012 at 6:59
  • 2
    Issue persists with setTimeout
    – TaylorMac
    Apr 30, 2014 at 20:54
0

iOS6 Safari suffers from a bug that kills timers that are created while a page is scrolling.

There is a fix to this problem provided by kTmnh by recreating timers after scrolling finishes

https://gist.github.com/3798925.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.