Skip to content

Commit b105253

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

File tree

3 files changed

+240
-47
lines changed

3 files changed

+240
-47
lines changed

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

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

191277
:::tip
192278

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

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.
281+
- The Animate API may not take effect, possibly because `getElementById` failed to select the node:
282+
- The ID selector might be incorrect
283+
- 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.
197284

198285
:::
199286

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

Lines changed: 100 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,115 @@ 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() 调用 <VersionBadge>3.4</VersionBadge>
182183

183-
- Animate API 与 CSS Animation 会互相覆盖,后生效的那一方会覆盖前者。
184+
**Lynx 3.4** 版本后,`animate()` 可以通过 `createSelectorQuery()` 来调用。
185+
186+
**该方式属于实验性功能。**
184187

185-
- 每次调用 `lynx.getElementById("test").animate` 都会生成一个新的 `Animation` 对象。
188+
```js
189+
const ani1 = lynx.createAnimation(
190+
'ani1',
191+
[
192+
{
193+
transform: 'translateY(0px)',
194+
},
195+
{
196+
transform: 'translateY(-150px)',
197+
},
198+
],
199+
{
200+
name: 'js-animation-1',
201+
duration: 3000,
202+
iterations: 'infinite',
203+
easing: 'cubic-bezier(.64, .57, .67, 1.53)',
204+
fill: 'forwards',
205+
},
206+
);
186207

187-
- Animate Api 暂只支持创建一个动画,未来会支持创建多个。因此现在若对一个节点多次调用 `lynx.getElementById("test").animate`,最后创建的动画会覆盖前面的动画。
208+
// start
209+
this.createSelectorQuery().select('#test').animate([ani1]).exec();
210+
// pause
211+
this.createSelectorQuery()
212+
.select('#test')
213+
.pauseAnimation(['js-animation-1'])
214+
.exec();
215+
```
188216

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

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

193-
:::
221+
**该方式属于实验性功能。**
222+
223+
```js
224+
const ani1 = lynx.createAnimation(
225+
'ani1',
226+
[
227+
{
228+
transform: 'translateY(0px)',
229+
},
230+
{
231+
transform: 'translateY(-150px)',
232+
},
233+
],
234+
{
235+
name: 'js-animation-1',
236+
duration: 3000,
237+
iterations: 'infinite',
238+
easing: 'cubic-bezier(.64, .57, .67, 1.53)',
239+
fill: 'forwards',
240+
},
241+
);
242+
243+
const ani2 = lynx.createAnimation(
244+
'ani2',
245+
[
246+
{
247+
'background-color': 'red',
248+
},
249+
{
250+
'background-color': 'blue',
251+
},
252+
],
253+
{
254+
name: 'js-animation-2',
255+
duration: 3000,
256+
easing: 'linear',
257+
fill: 'forwards',
258+
iterations: 'infinite',
259+
},
260+
);
261+
262+
// start
263+
this.createSelectorQuery().select('#test').animate([ani1, ani2]).exec();
264+
// pause
265+
this.createSelectorQuery()
266+
.select('#test')
267+
.pauseAnimation(['js-animation-1', 'js-animation-2'])
268+
.exec();
269+
```
270+
271+
## 动画事件
272+
273+
Animate API 的事件和 CSS Animation [动画事件](../event/animation-event#animation-动画)相同。
274+
275+
## 其他信息
194276

195277
:::tip
196278

197-
Animate API 不生效,可能是 getElementById 未能选中节点:
279+
- Animate API 与 CSS Animation 会互相覆盖,后生效的那一方会覆盖前者。
198280

199-
- 可能是 ID 选择器不正确
200-
- 可能是 ID 选择器的值依赖复杂 JS 表达式,导致 ID 选择器的值无法在首屏得到,此时若 getElementById 的时机过早 (如在 ComponentDidMount),则可能找不到节点
281+
- Animate API 不生效,可能是 getElementById 未能选中节点:
282+
- 可能是 ID 选择器不正确
283+
- 可能是 ID 选择器的值依赖复杂 JS 表达式,导致 ID 选择器的值无法在首屏得到,此时若 getElementById 的时机过早 (如在 ComponentDidMount),则可能找不到节点
201284

202285
:::
203286

@@ -211,3 +294,4 @@ Animate API 不生效,可能是 getElementById 未能选中节点:
211294
import { LegacyCompatTable } from '@lynx';
212295

213296
<LegacyCompatTable metadata="lynx-api/lynx/animateAPI" />
297+
```

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)