0%

safari setInterval 不准的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
var startTime = new Date().getTime();
var count = 0;
setInterval(function(){
var i = 0;
while(i++ < 100000000);
}, 0);
function fixed() {
count++;
var offset = new Date().getTime() - (startTime + count * 1000);
var nextTime = 1000 - offset;
if (nextTime < 0) nextTime = 0;
setTimeout(fixed, nextTime);

console.log(new Date().getTime() - (startTime + count * 1000));
}
setTimeout(fixed, 1000);

参考

不会被 iOS 停掉的网页定时器

坚持技术分享,您的支持将鼓励我继续创作!

欢迎关注我的其它发布渠道