javascript iOS 6 Safari,setInterval 不会被触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12683510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS 6 safari, setInterval doesn't get fired
提问by Johnny
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?
似乎如果我正在滚动window
,window.setInterval
在滚动发生时或之后不会被附加/触发。有没有其他人看到同样的问题?
I mean...
我是说...
- What could be causeing this?
- What can I do to fix this?
- 这可能是什么原因造成的?
- 我能做些什么来解决这个问题?
回答by jimp
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.
iOS 会停止几乎所有响应用户触摸的操作,以确保其响应灵敏。setInterval 问题是已知的,并且似乎没有解决方法。
setInterval pauses in iphone/ipad (mobile Safari) during scrolling
滚动期间在 iphone/ipad(移动 Safari)中的 setInterval 暂停
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).
在“冻结”期间,一旦用户释放屏幕,计时器将不会赶上。错过的事件不会被推迟,而是完全丢失(一个错误)。
回答by darnlotusblossom
Found this (scary but amazing) workaround, and it's working for me in iOS 6.0:
找到了这个(可怕但惊人的)解决方法,它在 iOS 6.0 中对我有用:
回答by Mithun Sreedharan
iOS6 Safari suffers from a bug that kills timers that are created while a page is scrolling.
iOS6 Safari 存在一个错误,该错误会杀死在页面滚动时创建的计时器。
There is a fix to this problem provided by kTmnh by recreating timers after scrolling finishes
kTmnh 通过在滚动完成后重新创建计时器来解决此问题
回答by Nathaniel
I'm not completely sure, but you could use a setTimeout
instead of setInterval
? It's generally bad practice to use setInterval anyway.
我不完全确定,但您可以使用 asetTimeout
代替setInterval
? 无论如何,使用 setInterval 通常是不好的做法。
var delay = 100;
(function callee() {
setTimeout(callee, delay);
})();