1e41f4b71Sopenharmony_ci# image-animator 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **\<image-animator>** component is used to provide an image frame animator. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciNot supported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Attributes 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory| Description | 18e41f4b71Sopenharmony_ci| --------------------- | -------------------------- | -------- | ---- | ------------------------------------------------------------ | 19e41f4b71Sopenharmony_ci| images | Array<ImageFrame> | - | Yes | Image frame information. The frame information includes the image path, size, and location. The supported image formats include PNG, JPG, and BMP. For details about **ImageFrame**, see Table 1.<br>**NOTE**<br>1. Use data binding, for example, **images = {{images}}**, to specify the image. Declare the corresponding variable in JavaScript: **images: [{src: "/common/heart-rate01.png"}, {src: "/common/heart-rate02.png"}]**.<br>2. Some lightweight devices are not able to parse images in their original format. To address this issue, in the application compilation phase, the image is directly compiled into a parseable bitmap (total number of bytes: image length x width x 4) and packed in the application installation package. Naturally, larger images result in a larger application installation package. To maintain a proper size of the application installation package, reduce the image resolution as appropriate.| 20e41f4b71Sopenharmony_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.| 21e41f4b71Sopenharmony_ci| reverse | boolean | false | No | Playback sequence.<br/>- **true**: Images are played from the last one to the first one.<br/>- **false**: Images are played from the first one to the last one.| 22e41f4b71Sopenharmony_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.<br> **false**: The image size is different from the component size. In this case, the width, height, top, and left attributes of each image must be set separately.| 23e41f4b71Sopenharmony_ci| duration | string | - | Yes | Single video playback duration, in seconds (s) or milliseconds (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.| 24e41f4b71Sopenharmony_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.| 25e41f4b71Sopenharmony_ci| id | string | - | No | Unique ID of the component. | 26e41f4b71Sopenharmony_ci| style | string | - | No | Style declaration of the component. | 27e41f4b71Sopenharmony_ci| class | string | - | No | Style class of the component, which is used to refer to a style table. | 28e41f4b71Sopenharmony_ci| ref | string | - | No | Reference information of child elements, which is registered with the parent component on **$refs**.| 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci **Table 1** ImageFrame 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 33e41f4b71Sopenharmony_ci| ------ | -------------- | ---- | ---- | ---------------- | 34e41f4b71Sopenharmony_ci| src | <uri> | - | Yes | Image path. | 35e41f4b71Sopenharmony_ci| width | <length> | 0 | No | Image width. | 36e41f4b71Sopenharmony_ci| height | <length> | 0 | No | Image height. | 37e41f4b71Sopenharmony_ci| top | <length> | 0 | No | Vertical coordinate of the image relative to the upper left corner of the component.| 38e41f4b71Sopenharmony_ci| left | <length> | 0 | No | Horizontal coordinate of the image relative to the upper left corner of the component.| 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci## Events 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name | Parameter | Description | 44e41f4b71Sopenharmony_ci| ------------------ | --------------------------------- | ----------- | 45e41f4b71Sopenharmony_ci| stop | - | Triggered when the frame animation stops | 46e41f4b71Sopenharmony_ci| click | - | Triggered when the component is clicked. | 47e41f4b71Sopenharmony_ci| longpress | - | Triggered when the component is long pressed. | 48e41f4b71Sopenharmony_ci| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component.| 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## Styles 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 54e41f4b71Sopenharmony_ci| ---------------------------------- | ---------------------------------------- | ----- | ---- | ---------------------------------------- | 55e41f4b71Sopenharmony_ci| width | <length> \| <percentage><sup>5+</sup> | - | No | Component width.<br><br>If this attribute is not set, the default value **0** is used. | 56e41f4b71Sopenharmony_ci| height | <length> \| <percentage><sup>5+</sup> | - | No | Component height.<br><br>If this attribute is not set, the default value **0** is used. | 57e41f4b71Sopenharmony_ci| padding | <length> | 0 | No | Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| 58e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | <length> | 0 | No | Left, top, right, and bottom padding. | 59e41f4b71Sopenharmony_ci| margin | <length> \| <percentage><sup>5+</sup> | 0 | No | Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| 60e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | No | Left, top, right, and bottom margins. | 61e41f4b71Sopenharmony_ci| border-width | <length> | 0 | No | Shorthand attribute to set the margin for all sides. | 62e41f4b71Sopenharmony_ci| border-color | <color> | black | No | Shorthand attribute to set the color for all borders. | 63e41f4b71Sopenharmony_ci| border-radius | <length> | - | No | Radius of round-corner borders. | 64e41f4b71Sopenharmony_ci| background-color | <color> | - | No | Background color. | 65e41f4b71Sopenharmony_ci| opacity<sup>5+</sup> | number | 1 | No | Opacity of an element. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent. | 66e41f4b71Sopenharmony_ci| display | string | flex | No | How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered| 67e41f4b71Sopenharmony_ci| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | No | left\|Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element.| 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci## Methods 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci| Name | Parameter | Description | 73e41f4b71Sopenharmony_ci| -------- | ---- | ---------------------------------------- | 74e41f4b71Sopenharmony_ci| start | - | Starts to play the frame animation of an image. If this method is called again, the playback starts from the first frame. | 75e41f4b71Sopenharmony_ci| pause | - | Pauses the frame animation playback of an image. | 76e41f4b71Sopenharmony_ci| stop | - | Stops the frame animation playback of an image. | 77e41f4b71Sopenharmony_ci| resume | - | Resumes the frame animation playback of an image. | 78e41f4b71Sopenharmony_ci| getState | - | Obtains the playback state. Available values are as follows:<br>- playing<br>- paused<br>- stopped| 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci## Example 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci```html 85e41f4b71Sopenharmony_ci<!-- xxx.hml --> 86e41f4b71Sopenharmony_ci<div class="container"> 87e41f4b71Sopenharmony_ci <image-animator class="animator" ref="animator" images="{{frames}}" duration="1s" /> 88e41f4b71Sopenharmony_ci <div class="btn-box"> 89e41f4b71Sopenharmony_ci <input class="btn" type="button" value="start" @click="handleStart" /> 90e41f4b71Sopenharmony_ci <input class="btn" type="button" value="stop" @click="handleStop" /> 91e41f4b71Sopenharmony_ci <input class="btn" type="button" value="pause" @click="handlePause" /> 92e41f4b71Sopenharmony_ci <input class="btn" type="button" value="resume" @click="handleResume" /> 93e41f4b71Sopenharmony_ci </div> 94e41f4b71Sopenharmony_ci</div> 95e41f4b71Sopenharmony_ci``` 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci```css 99e41f4b71Sopenharmony_ci/* xxx.css */ 100e41f4b71Sopenharmony_ci.container { 101e41f4b71Sopenharmony_ci flex-direction: column; 102e41f4b71Sopenharmony_ci justify-content: center; 103e41f4b71Sopenharmony_ci align-items: center; 104e41f4b71Sopenharmony_ci left: 0px; 105e41f4b71Sopenharmony_ci top: 0px; 106e41f4b71Sopenharmony_ci width: 454px; 107e41f4b71Sopenharmony_ci height: 454px; 108e41f4b71Sopenharmony_ci} 109e41f4b71Sopenharmony_ci.animator { 110e41f4b71Sopenharmony_ci width: 70px; 111e41f4b71Sopenharmony_ci height: 70px; 112e41f4b71Sopenharmony_ci} 113e41f4b71Sopenharmony_ci.btn-box { 114e41f4b71Sopenharmony_ci width: 264px; 115e41f4b71Sopenharmony_ci height: 120px; 116e41f4b71Sopenharmony_ci flex-wrap: wrap; 117e41f4b71Sopenharmony_ci justify-content: space-around; 118e41f4b71Sopenharmony_ci align-items: center; 119e41f4b71Sopenharmony_ci} 120e41f4b71Sopenharmony_ci.btn { 121e41f4b71Sopenharmony_ci border-radius: 8px; 122e41f4b71Sopenharmony_ci width: 120px; 123e41f4b71Sopenharmony_ci margin-top: 8px; 124e41f4b71Sopenharmony_ci} 125e41f4b71Sopenharmony_ci``` 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci```js 129e41f4b71Sopenharmony_ci//xxx.js 130e41f4b71Sopenharmony_ciexport default { 131e41f4b71Sopenharmony_ci data: { 132e41f4b71Sopenharmony_ci frames: [ 133e41f4b71Sopenharmony_ci { 134e41f4b71Sopenharmony_ci src: "/common/asserts/heart78.png", 135e41f4b71Sopenharmony_ci }, 136e41f4b71Sopenharmony_ci { 137e41f4b71Sopenharmony_ci src: "/common/asserts/heart79.png", 138e41f4b71Sopenharmony_ci }, 139e41f4b71Sopenharmony_ci { 140e41f4b71Sopenharmony_ci src: "/common/asserts/heart80.png", 141e41f4b71Sopenharmony_ci }, 142e41f4b71Sopenharmony_ci { 143e41f4b71Sopenharmony_ci src: "/common/asserts/heart81.png", 144e41f4b71Sopenharmony_ci }, 145e41f4b71Sopenharmony_ci { 146e41f4b71Sopenharmony_ci src: "/common/asserts/heart82.png", 147e41f4b71Sopenharmony_ci }, 148e41f4b71Sopenharmony_ci { 149e41f4b71Sopenharmony_ci src: "/common/asserts/heart83.png", 150e41f4b71Sopenharmony_ci }, 151e41f4b71Sopenharmony_ci { 152e41f4b71Sopenharmony_ci src: "/common/asserts/heart84.png", 153e41f4b71Sopenharmony_ci }, 154e41f4b71Sopenharmony_ci { 155e41f4b71Sopenharmony_ci src: "/common/asserts/heart85.png", 156e41f4b71Sopenharmony_ci }, 157e41f4b71Sopenharmony_ci { 158e41f4b71Sopenharmony_ci src: "/common/asserts/heart86.png", 159e41f4b71Sopenharmony_ci }, 160e41f4b71Sopenharmony_ci { 161e41f4b71Sopenharmony_ci src: "/common/asserts/heart87.png", 162e41f4b71Sopenharmony_ci }, 163e41f4b71Sopenharmony_ci { 164e41f4b71Sopenharmony_ci src: "/common/asserts/heart88.png", 165e41f4b71Sopenharmony_ci }, 166e41f4b71Sopenharmony_ci { 167e41f4b71Sopenharmony_ci src: "/common/asserts/heart89.png", 168e41f4b71Sopenharmony_ci }, 169e41f4b71Sopenharmony_ci { 170e41f4b71Sopenharmony_ci src: "/common/asserts/heart90.png", 171e41f4b71Sopenharmony_ci }, 172e41f4b71Sopenharmony_ci { 173e41f4b71Sopenharmony_ci src: "/common/asserts/heart91.png", 174e41f4b71Sopenharmony_ci }, 175e41f4b71Sopenharmony_ci { 176e41f4b71Sopenharmony_ci src: "/common/asserts/heart92.png", 177e41f4b71Sopenharmony_ci }, 178e41f4b71Sopenharmony_ci { 179e41f4b71Sopenharmony_ci src: "/common/asserts/heart93.png", 180e41f4b71Sopenharmony_ci }, 181e41f4b71Sopenharmony_ci { 182e41f4b71Sopenharmony_ci src: "/common/asserts/heart94.png", 183e41f4b71Sopenharmony_ci }, 184e41f4b71Sopenharmony_ci { 185e41f4b71Sopenharmony_ci src: "/common/asserts/heart95.png", 186e41f4b71Sopenharmony_ci }, 187e41f4b71Sopenharmony_ci { 188e41f4b71Sopenharmony_ci src: "/common/asserts/heart96.png", 189e41f4b71Sopenharmony_ci }, 190e41f4b71Sopenharmony_ci ], 191e41f4b71Sopenharmony_ci }, 192e41f4b71Sopenharmony_ci handleStart() { 193e41f4b71Sopenharmony_ci this.$refs.animator.start(); 194e41f4b71Sopenharmony_ci }, 195e41f4b71Sopenharmony_ci handlePause() { 196e41f4b71Sopenharmony_ci this.$refs.animator.pause(); 197e41f4b71Sopenharmony_ci }, 198e41f4b71Sopenharmony_ci handleResume() { 199e41f4b71Sopenharmony_ci this.$refs.animator.resume(); 200e41f4b71Sopenharmony_ci }, 201e41f4b71Sopenharmony_ci handleStop() { 202e41f4b71Sopenharmony_ci this.$refs.animator.stop(); 203e41f4b71Sopenharmony_ci }, 204e41f4b71Sopenharmony_ci}; 205e41f4b71Sopenharmony_ci``` 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci 208