这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

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

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
timeRemaining Chrome 47 Edge 79 Firefox 55
55
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 34 Safari 不支持 No WebView Android 47 Chrome Android 47 Firefox Android 55
55
Disabled ). To change preferences in Firefox, visit
Opera Android 34 Safari iOS 不支持 No Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. Background Tasks API
  2. IdleDeadline
  3. 特性
    1. didTimeout
  4. 方法
    1. timeRemaining()
  5. Related pages for Background Tasks
    1. Window.cancelIdleCallback()
    2. Window.requestIdleCallback()