最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - iOS 6 safari, setInterval doesn't get fired - Stack Overflow

programmeradmin1浏览0评论

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?

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?
Share Improve this question edited Nov 17, 2019 at 10:17 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Oct 2, 2012 at 1:49 JohnnyJohnny 2,9106 gold badges27 silver badges33 bronze badges 2
  • Maybe it will stop all scripts when scrolling to save memory and make the animation goes faster. Just guessing. – Derek 朕會功夫 Commented 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 Commented Oct 2, 2012 at 1:54
Add a comment  | 

4 Answers 4

Reset to default 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).

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

https://gist.github.com/3755461

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);
})();

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.

发布评论

评论列表(0)

  1. 暂无评论