aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/idledeadline/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/idledeadline/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/idledeadline/index.html')
-rw-r--r--files/zh-cn/web/api/idledeadline/index.html116
1 files changed, 116 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/idledeadline/index.html b/files/zh-cn/web/api/idledeadline/index.html
new file mode 100644
index 0000000000..e988592759
--- /dev/null
+++ b/files/zh-cn/web/api/idledeadline/index.html
@@ -0,0 +1,116 @@
+---
+title: IdleDeadline
+slug: Web/API/IdleDeadline
+translation_of: Web/API/IdleDeadline
+---
+<div>{{APIRef("Background Tasks")}}</div>
+
+<div id="interface_description">
+<p><code>IdleDeadline</code> interface 在 {{domxref("Window.requestIdleCallback()")}}被调用的时候做为一个<code>IdleDeadline</code> interface类型的参数传递给requestIdleCallback方法的回调函数。它提供了一个方法, 可以让你判断用户代理(浏览器)还剩余多少闲置时间可以用来执行耗时任务{{domxref("..timeRemaining", "timeRemaining()")}},{{domxref("IdleDeadline.didTimeout", "didTimeout")}}, didTimeout属性用来判断当前的回调函数是否被执行因为回调函数存在过期时间(requestIdleCallback的第二个参数用来指定执行超时时间,即回调函数在规定的时间内是否被执行,如果没有执行didTimeout属性将为ture,如果任务是急需完成的此时应该忽略剩余时间逻辑上强制执行回调函数)。</p>
+
+<p>学习更多的request callbacks工作原理请参考<a href="/en-US/docs/Web/API/Background_Tasks_API">Collaborative Scheduling of Background Tasks</a>.</p>
+</div>
+
+<h2 id="Properties">Properties</h2>
+
+<dl id="property_definitions">
+ <dt>{{domxref("IdleDeadline.didTimeout")}} {{ReadOnlyInline}}</dt>
+ <dd>一个Boolean类型当它的值为true的时候说明callback正在被执行(并且上一次执行回调函数执行的时候由于时间超时回调函数得不到执行),因为在执行requestIdleCallback回调的时候指定了超时时间并且时间已经超时。</dd>
+</dl>
+
+<h2 id="methods" name="methods">Methods</h2>
+
+<dl id="method_definitions">
+ <dt>{{domxref("IdleDeadline.timeRemaining()")}}</dt>
+ <dd>返回一个时间{{domxref("DOMHighResTimeStamp")}}, 并且是浮点类型的数值,它用来表示当前闲置周期的预估剩余毫秒数。如果idle period已经结束,则它的值是0。你的回调函数(传给requestIdleCallback的函数)可以重复的访问这个属性用来判断当前线程的闲置时间是否可以在结束前执行更多的任务。</dd>
+</dl>
+
+<dl id="method_definitions_obsolete">
+</dl>
+
+<h2 id="Example" name="Example">Example</h2>
+
+<p>实例<a href="/en-US/docs/Web/API/Background_Tasks_API#Example">complete example</a> (在 <a href="/en-US/docs/Web/API/Background_Tasks_API">Cooperative Scheduling of Background Tasks API</a>.文章内)</p>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("Background Tasks")}}</td>
+ <td>{{Spec2("Background Tasks")}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Edge</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>47</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatGeckoDesktop(53)}}<sup>[1]</sup></td>
+ <td>{{CompatNo}}</td>
+ <td>34</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>Firefox OS</th>
+ <th>IE Phone</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>53</td>
+ <td>55</td>
+ <td>{{CompatGeckoMobile(53)}}<sup>[1]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>37</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Idle callback功能在Firefox 53版本中添加,但是默认处于未启用状态. 通过设置<code>dom.requestIdleCallback.enabled</code> 属性为true 来启用该功能。Idle callback功能在Firefox 55版本中默认启用。</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/Background_Tasks_API">Cooperative Scheduling of Background Tasks API</a></li>
+ <li>{{domxref("Window.requestIdleCallback()")}}</li>
+ <li>{{domxref("Window.cancelIdleCallback()")}}</li>
+</ul>