Skip to content

Commit bdce4f3

Browse files
docs: update Animate API docs
Change-Id: Id08447becc68e639a61d48086df6f27346860e02
1 parent 75d5635 commit bdce4f3

File tree

3 files changed

+248
-47
lines changed

3 files changed

+248
-47
lines changed

docs/en/api/lynx-api/lynx/lynx-animate-api.mdx

Lines changed: 107 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
---
2-
title: animate()
3-
---
1+
import { VersionBadge } from '@lynx';
42

53
# animate()
64

@@ -119,6 +117,8 @@ The `Animation` object has the following methods:
119117

120118
## Example
121119

120+
### by getElementById()
121+
122122
```js
123123
let ani = lynx.getElementById('test').animate(
124124
[
@@ -172,28 +172,119 @@ ani.play();
172172
ani.cancel();
173173
```
174174

175-
## Animation Event
175+
::: note
176176

177-
The events for the `animate()` API are the same as the [animation events](../event/animation-event#animation) for CSS animations.
177+
- Each call to `getElementById("test").animate` will generate a new `Animation` object, and the later created animation will override the previous ones.
178+
- If you want to restart the same animation, you need to call `getElementById("test").animate` again to create a new `Animation` object.
178179

179-
## Other Infos
180+
:::
180181

181-
:::info
182+
### by createSelectorQuery()
182183

183-
- Animate Api and CSS Animation will override each other, and the one that takes effect later will override the former.
184-
- Each call to `getElementById("test").animate` will generate a new `Animation` object.
185-
- Animate Api currently only supports the creation of one animation, and will support the creation of multiple animations in the future. So now if `getElementById("test").animate` is called multiple times for a node, the last created animation will overwrite the previous animation.
186-
- After the animation corresponding to an `Animation` object ends, if you want to restart the same animation, you need to call `getElementById("test").animate` again to create a new `Animation` object.
187-
- Animate API currently only supports getElementById API, and the support for SelectQuery API is still being accessed.
184+
After **Lynx version 3.3**, the `animate()` can be called via the `createSelectorQuery()`.
188185

189-
:::
186+
**It's an experimental feature, and you should use it with caution.**
187+
188+
<VersionBadge>3.3</VersionBadge>
189+
190+
```js
191+
const ani1 = lynx.createAnimation(
192+
'ani1',
193+
[
194+
{
195+
transform: 'translateY(0px)',
196+
},
197+
{
198+
transform: 'translateY(-150px)',
199+
},
200+
],
201+
{
202+
name: 'js-animation-1',
203+
duration: 3000,
204+
iterations: 'infinite',
205+
easing: 'cubic-bezier(.64, .57, .67, 1.53)',
206+
fill: 'forwards',
207+
},
208+
);
209+
210+
// start
211+
this.createSelectorQuery().select('#test').animate([ani1]).exec();
212+
// pause
213+
this.createSelectorQuery()
214+
.select('#test')
215+
.pauseAnimation(['js-animation-1'])
216+
.exec();
217+
```
218+
219+
### Multiple animate()
220+
221+
After **Lynx version 3.3**, you can chain multiple animation with `createSelectorQuery()`.
222+
223+
**It's an experimental feature, and you should use it with caution.**
224+
225+
<VersionBadge>3.3</VersionBadge>
226+
227+
```js
228+
const ani1 = lynx.createAnimation(
229+
'ani1',
230+
[
231+
{
232+
transform: 'translateY(0px)',
233+
},
234+
{
235+
transform: 'translateY(-150px)',
236+
},
237+
],
238+
{
239+
name: 'js-animation-1',
240+
duration: 3000,
241+
iterations: 'infinite',
242+
easing: 'cubic-bezier(.64, .57, .67, 1.53)',
243+
fill: 'forwards',
244+
},
245+
);
246+
247+
const ani2 = lynx.createAnimation(
248+
'ani2',
249+
[
250+
{
251+
'background-color': 'red',
252+
},
253+
{
254+
'background-color': 'blue',
255+
},
256+
],
257+
{
258+
name: 'js-animation-2',
259+
duration: 3000,
260+
easing: 'linear',
261+
fill: 'forwards',
262+
iterations: 'infinite',
263+
},
264+
);
265+
266+
// start
267+
this.createSelectorQuery().select('#test').animate([ani1, ani2]).exec();
268+
// pause
269+
this.createSelectorQuery()
270+
.select('#test')
271+
.pauseAnimation(['js-animation-1', 'js-animation-2'])
272+
.exec();
273+
```
274+
275+
## Animation Event
276+
277+
The events for the `animate()` API are the same as the [animation events](../event/animation-event#animation) for CSS animations.
278+
279+
## Other Infos
190280

191281
:::tip
192282

193-
The Animate API may not take effect, possibly because `getElementById` failed to select the node:
283+
- Animate Api and CSS Animation will override each other, and the one that takes effect later will override the former.
194284

195-
- The ID selector might be incorrect
196-
- The value of the ID selector might depend on a complex JS expression, causing the value of the ID selector not to be available on the first screen. In this case, if getElementById is invoked too early (like in ComponentDidMount), it might not find the node.
285+
- The Animate API may not take effect, possibly because `getElementById` failed to select the node:
286+
- The ID selector might be incorrect
287+
- The value of the ID selector might depend on a complex JS expression, causing the value of the ID selector not to be available on the first screen. In this case, if getElementById is invoked too early (like in ComponentDidMount), it might not find the node.
197288

198289
:::
199290

docs/zh/api/lynx-api/lynx/lynx-animate-api.mdx

Lines changed: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
---
2-
title: animate()
3-
---
1+
import { VersionBadge } from '@lynx';
42

53
# animate()
64

@@ -119,6 +117,8 @@ element.animate([
119117

120118
## 示例
121119

120+
### 通过 getElementById() 调用
121+
122122
```js
123123
let ani = lynx.getElementById('test').animate(
124124
[
@@ -172,32 +172,119 @@ ani.play();
172172
ani.cancel();
173173
```
174174

175-
## 动画事件
175+
:::note
176176

177-
Animate API 的事件和 CSS Animation [动画事件](../event/animation-event#animation-动画)相同。
177+
- 每次调用 `lynx.getElementById("test").animate` 都会生成一个新的 `Animation` 对象,同时后面创建的动画会覆盖前面创建的动画。
178+
- 如果想重启一个同样的动画,需要重新调用 `lynx.getElementById("test").animate` 来创建一个新的 `Animation` 对象。。
178179

179-
## 其他信息
180+
:::
180181

181-
:::info
182+
### 通过 createSelectorQuery() 调用
182183

183-
- Animate API 与 CSS Animation 会互相覆盖,后生效的那一方会覆盖前者。
184+
**Lynx 3.3** 版本后,`animate()` 可以通过 `createSelectorQuery()` 来调用。
185+
186+
**该方式属于实验性功能。**
187+
188+
<VersionBadge>3.3</VersionBadge>
189+
```js
190+
const ani1 = lynx.createAnimation(
191+
'ani1',
192+
[
193+
{
194+
transform: 'translateY(0px)',
195+
},
196+
{
197+
transform: 'translateY(-150px)',
198+
},
199+
],
200+
{
201+
name: 'js-animation-1',
202+
duration: 3000,
203+
iterations: 'infinite',
204+
easing: 'cubic-bezier(.64, .57, .67, 1.53)',
205+
fill: 'forwards',
206+
},
207+
);
184208

185-
- 每次调用 `lynx.getElementById("test").animate` 都会生成一个新的 `Animation` 对象。
209+
// start
210+
this.createSelectorQuery().select('#test').animate([ani1]).exec();
211+
// pause
212+
this.createSelectorQuery()
213+
.select('#test')
214+
.pauseAnimation(['js-animation-1'])
215+
.exec();
186216

187-
- Animate Api 暂只支持创建一个动画,未来会支持创建多个。因此现在若对一个节点多次调用 `lynx.getElementById("test").animate`,最后创建的动画会覆盖前面的动画。
217+
````
188218

189-
- 一个 `Animation` 对象对应的动画结束后,若想重启一个同样的动画,需要重新调用 `lynx.getElementById("test").animate` 创建一个新的 `Animation` 对象。
219+
### 多动画 Multiple animate
190220

191-
- Animate API 暂只支持 getElementById API,对 SelectQuery API 的支持还未接入
221+
**Lynx 3.3** 版本后,可以通过 `createSelectorQuery()` 来在一个节点上同时启动多个动画
192222

193-
:::
223+
**该方式属于实验性功能。**
224+
225+
<VersionBadge>3.3</VersionBadge>
226+
227+
```js
228+
const ani1 = lynx.createAnimation(
229+
'ani1',
230+
[
231+
{
232+
transform: 'translateY(0px)',
233+
},
234+
{
235+
transform: 'translateY(-150px)',
236+
},
237+
],
238+
{
239+
name: 'js-animation-1',
240+
duration: 3000,
241+
iterations: 'infinite',
242+
easing: 'cubic-bezier(.64, .57, .67, 1.53)',
243+
fill: 'forwards',
244+
},
245+
);
246+
247+
const ani2 = lynx.createAnimation(
248+
'ani2',
249+
[
250+
{
251+
'background-color': 'red',
252+
},
253+
{
254+
'background-color': 'blue',
255+
},
256+
],
257+
{
258+
name: 'js-animation-2',
259+
duration: 3000,
260+
easing: 'linear',
261+
fill: 'forwards',
262+
iterations: 'infinite',
263+
},
264+
);
265+
266+
// start
267+
this.createSelectorQuery().select('#test').animate([ani1, ani2]).exec();
268+
// pause
269+
this.createSelectorQuery()
270+
.select('#test')
271+
.pauseAnimation(['js-animation-1', 'js-animation-2'])
272+
.exec();
273+
````
274+
275+
## 动画事件
276+
277+
Animate API 的事件和 CSS Animation [动画事件](../event/animation-event#animation-动画)相同。
278+
279+
## 其他信息
194280
195281
:::tip
196282
197-
Animate API 不生效,可能是 getElementById 未能选中节点:
283+
- Animate API 与 CSS Animation 会互相覆盖,后生效的那一方会覆盖前者。
198284
199-
- 可能是 ID 选择器不正确
200-
- 可能是 ID 选择器的值依赖复杂 JS 表达式,导致 ID 选择器的值无法在首屏得到,此时若 getElementById 的时机过早 (如在 ComponentDidMount),则可能找不到节点
285+
- Animate API 不生效,可能是 getElementById 未能选中节点:
286+
- 可能是 ID 选择器不正确
287+
- 可能是 ID 选择器的值依赖复杂 JS 表达式,导致 ID 选择器的值无法在首屏得到,此时若 getElementById 的时机过早 (如在 ComponentDidMount),则可能找不到节点
201288
202289
:::
203290
@@ -211,3 +298,4 @@ Animate API 不生效,可能是 getElementById 未能选中节点:
211298
import { LegacyCompatTable } from '@lynx';
212299
213300
<LegacyCompatTable metadata="lynx-api/lynx/animateAPI" />
301+
```

packages/lynx-compat-data/lynx-api/lynx/animateAPI.json

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@
22
"lynx-api": {
33
"lynx": {
44
"animateAPI": {
5-
"__compat": {
6-
"description": "Used to import modules.",
7-
"lynx_path": "api/lynx-api/lynx/lynx-animate_api",
8-
"support": {
9-
"android": {
10-
"version_added": "1.6"
11-
},
12-
"ios": {
13-
"version_added": "1.6"
14-
},
15-
"harmony": {
16-
"version_added": "3.4"
17-
},
18-
"web_lynx": {
19-
"version_added": false
5+
"compat": {
6+
"__compat": {
7+
"description": "Used to import modules.",
8+
"lynx_path": "api/lynx-api/lynx/lynx-animate_api",
9+
"support": {
10+
"android": {
11+
"version_added": "1.6"
12+
},
13+
"ios": {
14+
"version_added": "1.6"
15+
},
16+
"harmony": {
17+
"version_added": "3.4"
18+
},
19+
"web_lynx": {
20+
"version_added": false
21+
}
22+
}
23+
}
24+
},
25+
"multiple animation implementation": {
26+
"__compat": {
27+
"description": "Multiple animate",
28+
"lynx_path": "api/lynx-api/lynx/lynx-animate_api",
29+
"support": {
30+
"android": {
31+
"version_added": "3.4"
32+
},
33+
"ios": {
34+
"version_added": "3.4"
35+
},
36+
"harmony": {
37+
"version_added": "3.4"
38+
},
39+
"web_lynx": {
40+
"version_added": false
41+
}
2042
}
2143
}
2244
}

0 commit comments

Comments
 (0)