简体   繁体   中英

setTimeout on Mobile

I am using a simple setTimeOut() to prevent blocking of the UI like this:

setTimeout(function () {
  somefunction(m);
}, 0);

This works fine in IE and other browsers. But the UI is still blocked in mobile browsers such as chrome mobile and galaxy sIII built-in webkit browser. Any ideas why?

Due to the nature of mobile browsers which have a built-in delay, you always need to set delay higher than zero.

setTimeout(function () {
  somefunction(m);
}, 10);

Edit: As @Doorknob mentioned in his comment, 10ms would be fine in order not cause more delay when setting value higher than 100ms.

Timeout of 0 is not helping, timeout is in milliseconds. Also would be able to help whats your callback function trying to do, if your callback function is holding on to the dom , after timeout interval also you would experience the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM