aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/cancelanimationframe/index.html
blob: 95d38eb70ff6aa2272f844c7e4de89ac338f4e3c (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
---
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>

{{Compat("api.Window.cancelAnimationFrame")}}

<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>