iOS 6 safari, setInterval doesn't get fired

2020-02-26 00:11发布

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?

4条回答
再贱就再见
2楼-- · 2020-02-26 00:51

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

https://gist.github.com/3755461

查看更多
成全新的幸福
3楼-- · 2020-02-26 01:01

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

查看更多
女痞
4楼-- · 2020-02-26 01:04

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);
})();
查看更多
啃猪蹄的小仙女
5楼-- · 2020-02-26 01:08

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.

查看更多
登录 后发表回答