1e41f4b71Sopenharmony_ci# image-animator
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci>  **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThe **\<image-animator>** component is used to provide an image frame animator.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Attributes
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| Name                    | Type                        | Default Value     | Mandatory  | Description                                      |
20e41f4b71Sopenharmony_ci| ---------------------- | -------------------------- | -------- | ---- | ---------------------------------------- |
21e41f4b71Sopenharmony_ci| images                 | Array&lt;ImageFrame&gt;    | -        | Yes   | Image frame information. The frame information includes the image path, size, and location. The supported image formats include PNG and JPG.  <br>Set this attribute using data binding.<br>- Reference image resources in the HML file: **images = {{images}}**.<br>- Declare the corresponding variables in the JS file:<br>**images: [{src: "/common/heart-rate01.png",duration:"100"}]** Since API version 6,the duration (in milliseconds) per image frame can be set.|
22e41f4b71Sopenharmony_ci| predecode<sup>6+</sup> | number                     | 0        | No   | Whether to enable pre-decoding. The default value **0** indicates that pre-decoding is disabled. The value **2** indicates that two images following the currently playing frame will be cached in advance to improve performance.|
23e41f4b71Sopenharmony_ci| iteration              | number \| string | infinite | No   | Number of times that the frame animation is played. **number** indicates a fixed number of playback operations, and **infinite** indicates an unlimited number of playback operations.|
24e41f4b71Sopenharmony_ci| reverse                | boolean                    | false    | No   | Playback sequence. The value **false** indicates that images are played from the first one to the last one, and **true** indicates that images are played from the last one to the first one.|
25e41f4b71Sopenharmony_ci| fixedsize              | boolean                    | true     | No   | Whether the image size is the same as the component size.<br> **true**: The image size is the same as the component size. In this case, the width, height, top, and left attributes of the image are invalid. **false**: The width, height, top, and left attributes of each image must be set separately.|
26e41f4b71Sopenharmony_ci| duration               | string                     | -        | Yes   | Single video playback duration. The unit can be s (standing for seconds) or ms. The default unit is ms. If the value is **0**, no image is played. The value change takes effect only at the start of the next cycle. If image-specific durations have been set, the settings of this attribute do not take effect. |
27e41f4b71Sopenharmony_ci| fillmode<sup>5+</sup>  | string                     | forwards | No   | Status of the frame animation after its playback is complete. Available values are as follows:<br>- **none**: Restores to the initial status.<br>- **forwards**: Retains the ending status defined for the last key frame.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Table 1** ImageFrame
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| Name                   | Type            | Default Value | Mandatory  | Description                    |
32e41f4b71Sopenharmony_ci| --------------------- | -------------- | ---- | ---- | ---------------------- |
33e41f4b71Sopenharmony_ci| src                   | &lt;uri&gt;    | -    | Yes   | Image path. The image format can be SVG, PNG, JPG, or HEIF.|
34e41f4b71Sopenharmony_ci| width                 | &lt;length&gt; | 0    | No   | Image width.                 |
35e41f4b71Sopenharmony_ci| height                | &lt;length&gt; | 0    | No   | Image height.                 |
36e41f4b71Sopenharmony_ci| top                   | &lt;length&gt; | 0    | No   | Vertical coordinate of the image relative to the upper left corner of the component.      |
37e41f4b71Sopenharmony_ci| left                  | &lt;length&gt; | 0    | No   | Horizontal coordinate of the image relative to the upper left corner of the component.      |
38e41f4b71Sopenharmony_ci| duration<sup>6+</sup> | number         | -    | No   | Playback duration of each image frame, in milliseconds.      |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci## Styles
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciThe [universal styles](js-components-common-styles.md) are supported.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci## Events
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciIn addition to the [universal events](js-components-common-events.md), the following events are supported.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci| Name    | Parameter  | Description       |
51e41f4b71Sopenharmony_ci| ------ | ---- | --------- |
52e41f4b71Sopenharmony_ci| start  | -    | Triggered when the frame animation starts.|
53e41f4b71Sopenharmony_ci| pause  | -    | Triggered when the frame animation pauses.|
54e41f4b71Sopenharmony_ci| stop   | -    | Triggered when the frame animation stops.|
55e41f4b71Sopenharmony_ci| resume | -    | Triggered when the frame animation resumes.|
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci## Methods
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ciIn addition to the [universal methods](js-components-common-methods.md), the following methods are supported.
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci| Name      | Parameter  | Description                                      |
63e41f4b71Sopenharmony_ci| -------- | ---- | ---------------------------------------- |
64e41f4b71Sopenharmony_ci| start    | -    | Starts to play the frame animation of an image. If this method is called again, the playback starts from the first frame.              |
65e41f4b71Sopenharmony_ci| pause    | -    | Pauses the frame animation playback of an image.                              |
66e41f4b71Sopenharmony_ci| stop     | -    | Stops the frame animation playback of an image.                              |
67e41f4b71Sopenharmony_ci| resume   | -    | Resumes the frame animation playback of an image.                                |
68e41f4b71Sopenharmony_ci| getState | -    | Obtains the playback state. Available values are as follows:<br>- playing<br>- paused<br>- stopped|
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci## Example
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci```html
74e41f4b71Sopenharmony_ci<!-- xxx.hml -->
75e41f4b71Sopenharmony_ci<div class="container">
76e41f4b71Sopenharmony_ci  <image-animator class="animator" ref="animator" images="{{frames}}" duration="1s" />
77e41f4b71Sopenharmony_ci  <div class="btn-box">
78e41f4b71Sopenharmony_ci    <input class="btn" type="button" value="start" @click="handleStart" />
79e41f4b71Sopenharmony_ci    <input class="btn" type="button" value="stop" @click="handleStop" />
80e41f4b71Sopenharmony_ci    <input class="btn" type="button" value="pause" @click="handlePause" />
81e41f4b71Sopenharmony_ci    <input class="btn" type="button" value="resume" @click="handleResume" />
82e41f4b71Sopenharmony_ci  </div>
83e41f4b71Sopenharmony_ci</div>
84e41f4b71Sopenharmony_ci```
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci```css
87e41f4b71Sopenharmony_ci/* xxx.css */
88e41f4b71Sopenharmony_ci.container {
89e41f4b71Sopenharmony_ci  flex-direction: column;
90e41f4b71Sopenharmony_ci  justify-content: center;
91e41f4b71Sopenharmony_ci  align-items: center;
92e41f4b71Sopenharmony_ci  left: 0px;
93e41f4b71Sopenharmony_ci  top: 0px;
94e41f4b71Sopenharmony_ci  width: 454px;
95e41f4b71Sopenharmony_ci  height: 454px;
96e41f4b71Sopenharmony_ci}
97e41f4b71Sopenharmony_ci.animator {
98e41f4b71Sopenharmony_ci  width: 70px;
99e41f4b71Sopenharmony_ci  height: 70px;
100e41f4b71Sopenharmony_ci}
101e41f4b71Sopenharmony_ci.btn-box {
102e41f4b71Sopenharmony_ci  width: 264px;
103e41f4b71Sopenharmony_ci  height: 120px;
104e41f4b71Sopenharmony_ci  flex-wrap: wrap;
105e41f4b71Sopenharmony_ci  justify-content: space-around;
106e41f4b71Sopenharmony_ci  align-items: center;
107e41f4b71Sopenharmony_ci}
108e41f4b71Sopenharmony_ci.btn {
109e41f4b71Sopenharmony_ci  border-radius: 8px;
110e41f4b71Sopenharmony_ci  width: 120px;
111e41f4b71Sopenharmony_ci  margin-top: 8px;
112e41f4b71Sopenharmony_ci}
113e41f4b71Sopenharmony_ci```
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci```js
116e41f4b71Sopenharmony_ci//xxx.js
117e41f4b71Sopenharmony_ciexport default {
118e41f4b71Sopenharmony_ci  data: {
119e41f4b71Sopenharmony_ci    frames: [
120e41f4b71Sopenharmony_ci      {
121e41f4b71Sopenharmony_ci        src: "/common/asserts/heart78.png",
122e41f4b71Sopenharmony_ci      },
123e41f4b71Sopenharmony_ci      {
124e41f4b71Sopenharmony_ci        src: "/common/asserts/heart79.png",
125e41f4b71Sopenharmony_ci      },
126e41f4b71Sopenharmony_ci      {
127e41f4b71Sopenharmony_ci        src: "/common/asserts/heart80.png",
128e41f4b71Sopenharmony_ci      },
129e41f4b71Sopenharmony_ci      {
130e41f4b71Sopenharmony_ci        src: "/common/asserts/heart81.png",
131e41f4b71Sopenharmony_ci      },
132e41f4b71Sopenharmony_ci      {
133e41f4b71Sopenharmony_ci        src: "/common/asserts/heart82.png",
134e41f4b71Sopenharmony_ci      },
135e41f4b71Sopenharmony_ci      {
136e41f4b71Sopenharmony_ci        src: "/common/asserts/heart83.png",
137e41f4b71Sopenharmony_ci      },
138e41f4b71Sopenharmony_ci      {
139e41f4b71Sopenharmony_ci        src: "/common/asserts/heart84.png",
140e41f4b71Sopenharmony_ci      },
141e41f4b71Sopenharmony_ci      {
142e41f4b71Sopenharmony_ci        src: "/common/asserts/heart85.png",
143e41f4b71Sopenharmony_ci      },
144e41f4b71Sopenharmony_ci      {
145e41f4b71Sopenharmony_ci        src: "/common/asserts/heart86.png",
146e41f4b71Sopenharmony_ci      },
147e41f4b71Sopenharmony_ci      {
148e41f4b71Sopenharmony_ci        src: "/common/asserts/heart87.png",
149e41f4b71Sopenharmony_ci      },
150e41f4b71Sopenharmony_ci      {
151e41f4b71Sopenharmony_ci        src: "/common/asserts/heart88.png",
152e41f4b71Sopenharmony_ci      },
153e41f4b71Sopenharmony_ci      {
154e41f4b71Sopenharmony_ci        src: "/common/asserts/heart89.png",
155e41f4b71Sopenharmony_ci      },
156e41f4b71Sopenharmony_ci      {
157e41f4b71Sopenharmony_ci        src: "/common/asserts/heart90.png",
158e41f4b71Sopenharmony_ci      },
159e41f4b71Sopenharmony_ci      {
160e41f4b71Sopenharmony_ci        src: "/common/asserts/heart91.png",
161e41f4b71Sopenharmony_ci      },
162e41f4b71Sopenharmony_ci      {
163e41f4b71Sopenharmony_ci        src: "/common/asserts/heart92.png",
164e41f4b71Sopenharmony_ci      },
165e41f4b71Sopenharmony_ci      {
166e41f4b71Sopenharmony_ci        src: "/common/asserts/heart93.png",
167e41f4b71Sopenharmony_ci      },
168e41f4b71Sopenharmony_ci      {
169e41f4b71Sopenharmony_ci        src: "/common/asserts/heart94.png",
170e41f4b71Sopenharmony_ci      },
171e41f4b71Sopenharmony_ci      {
172e41f4b71Sopenharmony_ci        src: "/common/asserts/heart95.png",
173e41f4b71Sopenharmony_ci      },
174e41f4b71Sopenharmony_ci      {
175e41f4b71Sopenharmony_ci        src: "/common/asserts/heart96.png",
176e41f4b71Sopenharmony_ci      },
177e41f4b71Sopenharmony_ci    ],
178e41f4b71Sopenharmony_ci  },
179e41f4b71Sopenharmony_ci  handleStart() {
180e41f4b71Sopenharmony_ci    this.$refs.animator.start();
181e41f4b71Sopenharmony_ci  },
182e41f4b71Sopenharmony_ci  handlePause() {
183e41f4b71Sopenharmony_ci    this.$refs.animator.pause();
184e41f4b71Sopenharmony_ci  },
185e41f4b71Sopenharmony_ci  handleResume() {
186e41f4b71Sopenharmony_ci    this.$refs.animator.resume();
187e41f4b71Sopenharmony_ci  },
188e41f4b71Sopenharmony_ci  handleStop() {
189e41f4b71Sopenharmony_ci    this.$refs.animator.stop();
190e41f4b71Sopenharmony_ci  },
191e41f4b71Sopenharmony_ci};
192e41f4b71Sopenharmony_ci```
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci![image-animator](figures/image-animator.gif)
195