这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
timeRemaining
()
method on the
IdleDeadline
interface returns the estimated number of milliseconds remaining in the current idle period. The callback can call this method at any time to determine how much time it can continue to work before it must return. For example, if the callback finishes a task and has another one to begin, it can call
timeRemaining()
to see if there's enough time to complete the next task. If there isn't, the callback can just return immediately, or look for other work to do with the remaining time.
By the time
timeRemaining()
reaches 0, it is suggested that the callback should return control to the user agent's event loop.
timeRemaining = IdleDeadline.timeRemaining();
A
DOMHighResTimeStamp
value (which is a floating-point number) representing the number of milliseconds the user agent estimates are left in the current idle period. The value is ideally accurate to within about 5 microseconds.
若
IdleDeadline
对象的
didTimeout
property is true, this method returns zero.
See our complete example in the article Cooperative Scheduling of Background Tasks API .
| 规范 | 状态 | 注释 |
|---|---|---|
| Cooperative Scheduling of Background Tasks | Proposed Recommendation |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
timeRemaining
|
Chrome 47 | Edge 79 |
Firefox
55
|
IE 不支持 No | Opera 34 | Safari 不支持 No | WebView Android 47 | Chrome Android 47 |
Firefox Android
55
|
Opera Android 34 | Safari iOS 不支持 No | Samsung Internet Android 5.0 |
完整支持
不支持
用户必须明确启用此特征。
IdleDeadline
Window.requestIdleCallback()
Window.cancelIdleCallback()
IdleDeadline
timeRemaining()