aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/animation/currenttime/index.html
blob: 25c3ca441d2ca12648f78aff0e02f410d71bfe60 (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
---
title: Animation.currentTime
slug: Web/API/Animation/currentTime
tags:
  - 动画
translation_of: Web/API/Animation/currentTime
---
<p>{{APIRef("Web Animations API")}}{{SeeCompatTable}}</p>

<p>Animation.currentTime属性返回或设置动画的当前时间值(以毫秒为单位),无论动画正在运行还是已暂停。</p>

<p>如果动画缺少{{domxref("AnimationTimeline", "timeline")}},处于非活动状态或尚未播放,则当前时间返回值为null。</p>

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

<pre class="syntaxbox">var <em>currentTime</em> = element.currentTime;
element.currentTime =<em> someValue;</em></pre>

<h3 id="值"></h3>

<p>表示当前时间的数字(以毫秒为单位),或为null。</p>

<h2 id="例子">例子</h2>

<p><a href="http://codepen.io/rachelnabors/pen/PNYGZQ?editors=0010">Drink Me/Eat Me game</a>中,爱丽丝的高度是可变动的,所以它可以从小到大或从大到小。 在游戏开始时,通过将她的动画的currentTime设置为她的keyframeEffect的持续时间的一半让她的高度设置在两个极端之间:</p>

<pre class="brush: js">aliceChange<strong>.currentTime</strong> = aliceChange.effect.timing.duration / 2;</pre>

<p>寻求动画的50%标记的更通用的方法:</p>

<pre class="brush: js">animation.currentTime =
  animation.effect.getComputedTiming().delay +
  animation.effect.getComputedTiming().activeDuration / 2;</pre>

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

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">说明</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Animations', '#dom-animation-currenttime', 'currentTime')}}</td>
   <td>{{Spec2("Web Animations")}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器支持">浏览器支持</h2>

<div>{{CompatibilityTable}}</div>

<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>{{CompatChrome(39.0)}}</td>
   <td>{{CompatGeckoDesktop(48)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</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>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(39.0)}}</td>
   <td>{{CompatGeckoMobile(48)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(39.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<p> </p>

<h2 id="相关内容" style="line-height: 30px; font-size: 2.14285714285714rem;">相关内容</h2>

<ul>
 <li>{{domxref("Animation")}} for other methods and properties you can use to control web page animation.</li>
 <li>{{domxref("Animation.startTime")}} for the time an animation is scheduled to start.</li>
 <li><a href="/en-US/docs/Web/API/Web_Animations_API">Web Animations API</a></li>
</ul>