aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/cancelanimationframe/index.html
blob: 0d98e5db24b6875aa1db28823f36c4a48851adc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: window.cancelAnimationFrame
slug: Web/API/Window/cancelAnimationFrame
translation_of: Web/API/Window/cancelAnimationFrame
---
<div>{{APIRef}}{{SeeCompatTable}}</div>

<h2 id="概述">概述</h2>

<p>取消一个先前通过调用{{ domxref("window.requestAnimationFrame()") }}方法添加到计划中的动画帧请求.</p>

<h2 id="语法">语法</h2>

<pre class="eval">window.mozCancelAnimationFrame(<em>requestID</em>);               // Firefox
</pre>

<h2 id="参数">参数</h2>

<dl>
 <dt><code>requestID</code></dt>
 <dd>先前调用{{ domxref("window.requestAnimationFrame()") }}方法时返回的ID.</dd>
</dl>

<h2 id="Notes" name="Notes">示例</h2>

<pre class="deki-transform">var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                            window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;

var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;

var start = window.mozAnimationStartTime;  // 只有Firefox支持mozAnimationStartTime属性,其他浏览器可以使用Date.now()来替代.

var myReq;
function step(timestamp) {
  var progress = timestamp - start;
  d.style.left = Math.min(progress/10, 200) + "px";
  if (progress &lt; 2000) {
    myReq = requestAnimationFrame(step);
  }
}
myReq = requestAnimationFrame(step);

window.cancelAnimationFrame(myReq);
</pre>

<h2 id="Browser_Compatibility" name="Browser_Compatibility">浏览器兼容性</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>
    <p>21.0 {{ property_prefix("webkit") }}</p>

    <p>24.0 脱前缀</p>
   </td>
   <td>
    <p>{{ CompatGeckoDesktop("11.0") }} {{ property_prefix("moz") }} </p>
   </td>
   <td>10</td>
   <td>{{ CompatUnknown() }}</td>
   <td>
    <p>6.0 {{ property_prefix("webkit") }}</p>
   </td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatUnknown() }}</td>
   <td>
    <p>{{ CompatUnknown() }}</p>
   </td>
   <td>{{ CompatGeckoMobile("11.0") }} {{ property_prefix("moz") }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatUnknown() }}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Specification" name="Specification">规范</h2>

<p>{{ spec("http://www.w3.org/TR/animation-timing/#cancelAnimationFrame", "Timing control for script-based animations: cancelAnimationFrame", "WD") }}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{ domxref("window.mozAnimationStartTime") }}</li>
 <li>{{ domxref("window.requestAnimationFrame()") }}</li>
</ul>