1e41f4b71Sopenharmony_ci# animate
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci>  **说明:**
5e41f4b71Sopenharmony_ci> 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci设置svg组件的属性动画。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## 权限列表
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## 子组件
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci不支持。
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## 属性
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
22e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
23e41f4b71Sopenharmony_ci| id | string | - | 否 | 组件的唯一标识。 |
24e41f4b71Sopenharmony_ci| attributeName | string | - | 否 | 设置需要进行动效的属性名。 |
25e41f4b71Sopenharmony_ci| begin | &lt;time&gt; | 0 | 否 | 设置动效的延迟时间。<br/>支持输入ms(毫秒)、s(秒)、m(分),默认为s(秒),其他格式不支持 |
26e41f4b71Sopenharmony_ci| dur | &lt;time&gt; | 0 | 否 | 设置动效持续时间,如果dur没设置,按照end-begin的结果作为持续时间,小于等于0时,动效不触发。<br/>支持输入ms(毫秒)、s(秒)、m(分),默认为s(秒),其他格式不支持 |
27e41f4b71Sopenharmony_ci| end | &lt;time&gt; | 0 | 否 | 设置动效多久时间后结束。支持输入ms(毫秒)、s(秒)、m(分),默认为s(秒),其他格式不支持 |
28e41f4b71Sopenharmony_ci| repeatCount | &lt;number&nbsp;\|&nbsp;indefinite&gt; | 1 | 否 | 设置动画播放的次数,默认无限次播放(indefinite),可通过设置为数值1仅播放一次。 |
29e41f4b71Sopenharmony_ci| fill | &lt;freeze&nbsp;\|&nbsp;remove&gt; | remove | 否 | 设置动画结束时的状态。 |
30e41f4b71Sopenharmony_ci| calcMode | &lt;discrete&nbsp;\|&nbsp;linear&nbsp;\|&nbsp;paced&nbsp;\|&nbsp;spline&gt; | linear | 否 | 设置动画的插值模式。<br/>discrete:阶跃,from值直接跳转到to的值;<br/>linear:线性;<br/>paced:线性,设置此项后keyTimes和keyPoints值无效<br/>spline:自定义贝塞尔曲线,spline点定义在keyTimes属性中,每个时间间隔控制点由keySplines定义 |
31e41f4b71Sopenharmony_ci| keyTimes | string | - | 否 | 设置关键帧动画的开始时间,值为0~1之间的数值用分号隔开,比如0;0.3;0.8;1。keyTimes、keySplines、values组合设置关键帧动画。keyTimes和values的个数保持一致。keySplines个数为keyTimes个数减一 |
32e41f4b71Sopenharmony_ci| keySplines | string | - | 否 | 与keyTimes相关联的一组贝塞尔控制点。定义每个关键帧的贝塞尔曲线,曲线之间用分号隔开。曲线内的两个控制掉格式为x1&nbsp;y1&nbsp;x2&nbsp;y2。比如0.5&nbsp;0&nbsp;0.5&nbsp;1;&nbsp;0.5&nbsp;0&nbsp;0.5&nbsp;1;0.5&nbsp;0&nbsp;0.5&nbsp;1 |
33e41f4b71Sopenharmony_ci| by | number | - | 否 | 在动画中对某一指定属性,添加相对偏移值,from默认为原属性值。 |
34e41f4b71Sopenharmony_ci| from | string | - | 否 | 设置需要进行动画的属性的开始值。<br/>如果已经设置了values属性,则from失效。 |
35e41f4b71Sopenharmony_ci| to | string | - | 否 | 设置需要进行动画的属性的结束值。<br/>如果已经设置了values属性,则to都失效。 |
36e41f4b71Sopenharmony_ci| values | string | - | 否 | 设置一组动画的变化值。格式为value1;value2;value3。 |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## 示例
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci```html
42e41f4b71Sopenharmony_ci<!-- xxx.hml -->
43e41f4b71Sopenharmony_ci<div class="container">
44e41f4b71Sopenharmony_ci  <svg width="400" height="400">
45e41f4b71Sopenharmony_ci    <rect x="20" y="20" width="100" height="100" fill="red" rx="0" ry="20">
46e41f4b71Sopenharmony_ci      <animate attributeName="rx" values="0;10;30;0" keyTimes="0;0.25;0.75;1" keySplines="0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1" dur="1000" repeatCount="indefinite">
47e41f4b71Sopenharmony_ci      </animate>
48e41f4b71Sopenharmony_ci    </rect>
49e41f4b71Sopenharmony_ci  </svg>
50e41f4b71Sopenharmony_ci</div>
51e41f4b71Sopenharmony_ci```
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci![zh-cn_image_0000001173324703](figures/zh-cn_image_0000001173324703.gif)
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci```html
58e41f4b71Sopenharmony_ci<!-- xxx.hml -->
59e41f4b71Sopenharmony_ci<div class="container">
60e41f4b71Sopenharmony_ci  <svg width="400" height="400">
61e41f4b71Sopenharmony_ci    <rect x="20" y="20" width="100" height="100" fill="red" rx="0" ry="20">
62e41f4b71Sopenharmony_ci      <animate attributeName="fill" from="red" to="blue" dur="1000" repeatCount="indefinite"></animate>
63e41f4b71Sopenharmony_ci      <animate attributeName="height" from="50" to="150" begin="500" end="1000" repeatCount="indefinite">  </animate>
64e41f4b71Sopenharmony_ci    </rect>
65e41f4b71Sopenharmony_ci  </svg>
66e41f4b71Sopenharmony_ci</div>
67e41f4b71Sopenharmony_ci```
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci![zh-cn_image_0000001167662852](figures/zh-cn_image_0000001167662852.gif)
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci```html
74e41f4b71Sopenharmony_ci<!-- xxx.hml -->
75e41f4b71Sopenharmony_ci<div class="container">
76e41f4b71Sopenharmony_ci  <svg width="400" height="400">
77e41f4b71Sopenharmony_ci    <rect x="20" y="20" width="100" height="100" fill="red" rx="0" ry="20">
78e41f4b71Sopenharmony_ci      <animate attributeName="rx" values="0;30" dur="1000" repeatCount="indefinite" fill="freeze" calcMode="linear"></animate>
79e41f4b71Sopenharmony_ci    </rect>
80e41f4b71Sopenharmony_ci  </svg>
81e41f4b71Sopenharmony_ci</div>
82e41f4b71Sopenharmony_ci```
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci![zh-cn_image_0000001127284938](figures/zh-cn_image_0000001127284938.gif)
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci```html
89e41f4b71Sopenharmony_ci<!-- xxx.hml -->
90e41f4b71Sopenharmony_ci<div class="container">
91e41f4b71Sopenharmony_ci  <svg fill="white" width="600" height="600">
92e41f4b71Sopenharmony_ci    <circle cx="60" cy="70" r="50" stroke-width="4" fill="white" stroke="blue">
93e41f4b71Sopenharmony_ci      <animate attributeName="r" from="0" to="50" dur="2000" repeatCount="indefinite"></animate>
94e41f4b71Sopenharmony_ci      <animate attributeName="cx" from="60" to="200" dur="2000" repeatCount="indefinite"></animate>
95e41f4b71Sopenharmony_ci    </circle>
96e41f4b71Sopenharmony_ci    <circle cx="60" cy="200" r="50" stroke-width="4" fill="white" stroke="blue">
97e41f4b71Sopenharmony_ci      <animate attributeName="stroke-width" from="4" to="10" calcMode="discrete" dur="2000" repeatCount="indefinite"></animate>
98e41f4b71Sopenharmony_ci      <animate attributeName="stroke" values="red;blue" dur="2000" repeatCount="indefinite"></animate>
99e41f4b71Sopenharmony_ci    </circle>
100e41f4b71Sopenharmony_ci    <circle cx="180" cy="200" r="50" stroke-width="10" stroke="red" stroke-dasharray="60 10" stroke-dashoffset="3">
101e41f4b71Sopenharmony_ci      <animate attributeName="stroke-opacity" from="1.0" to="0.5" dur="2000" repeatCount="indefinite"></animate>
102e41f4b71Sopenharmony_ci      <animate attributeName="stroke-dashoffset" values="30;0;30" dur="500" repeatCount="indefinite"></animate>
103e41f4b71Sopenharmony_ci     <animate attributeName="cx" from="180" to="400" dur="2000" repeatCount="indefinite"></animate>
104e41f4b71Sopenharmony_ci    </circle>
105e41f4b71Sopenharmony_ci    <circle cx="180" cy="200" r="5" fill="blue">
106e41f4b71Sopenharmony_ci      <animate attributeName="cx" from="180" to="400" dur="2000" repeatCount="indefinite"></animate>
107e41f4b71Sopenharmony_ci    </circle>
108e41f4b71Sopenharmony_ci    <circle cx="60" cy="380" r="50"  fill="blue">
109e41f4b71Sopenharmony_ci      <animate attributeName="fill" values="red;blue" dur="2000" repeatCount="indefinite"></animate>
110e41f4b71Sopenharmony_ci    </circle>
111e41f4b71Sopenharmony_ci    <circle cx="180" cy="380" r="50"  fill="blue">
112e41f4b71Sopenharmony_ci      <animate attributeName="fill-opacity" from="1.0" to="0.5" dur="2000" repeatCount="indefinite"></animate>
113e41f4b71Sopenharmony_ci    </circle>
114e41f4b71Sopenharmony_ci    </svg>
115e41f4b71Sopenharmony_ci</div>
116e41f4b71Sopenharmony_ci```
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci![zh-cn_image_0000001127125126](figures/zh-cn_image_0000001127125126.gif)
120