Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 safari, setInterval doesn't get fired

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?
like image 318
Johnny Avatar asked Oct 02 '12 01:10

Johnny


People also ask

How to work setInterval?

setInterval() The setInterval() method, offered on the Window and Worker interfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. This method returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval() .

How to call function in setInterval?

The setInterval() method calls a function at specified intervals (in milliseconds). The setInterval() method continues calling the function until clearInterval() is called, or the window is closed. 1 second = 1000 milliseconds.

How to unsubscribe setInterval?

Answer: Use the clearInterval() Method The setInterval() method returns an interval ID which uniquely identifies the interval. You can pass this interval ID to the global clearInterval() method to cancel or stop setInterval() call.


2 Answers

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).

like image 120
jimp Avatar answered Sep 28 '22 05:09

jimp


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

https://gist.github.com/3755461

like image 33
darnlotusblossom Avatar answered Sep 28 '22 05:09

darnlotusblossom