image-animator组件为图片帧动画播放器。具体用法请参考image-animator。
创建image-animator组件
在pages/index目录下的hml文件中创建一个image-animator组件,css文件中编写组件样式,js文件中引用图片。
<!-- xxx.hml -->
<div class="container">
<image-animator class="animator" images="{
{frames}}" duration="3s"/>
</div>
/* xxx.css */
.container {
width: 100%;
height: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #F1F3F5;
}
.animator {
width: 500px;
height: 500px;
}
// index.js
export default {
data: {
frames: [
{
src: "/common/landscape1.jpg",
},
{
src: "/common/landscape2.jpg",
}
],
},
};
设置image-animator组件属性
添加iteration(播放次数)、reverse(播放顺序)、fixedsize(图片大小是否固定为组件大小)、duration(播放时长)和fillmode(执行结束后的状态)属性,控制图片的播放效果。
<!-- xxx.hml -->
<div class="container">
<image-animator class="animator" fixedsize="false" iteration='2' reverse="false" ref="animator" fillmode="none" images="{
{frames}}" duration="5s" />
</div>
/* xxx.css */
.container {
width: 100%;
height: 100%;
flex-direction: column;
background-color: #F1F3F5;
}
.animator {
width: 500px;
height: 500px;
}
// index.js
export default {
data: {
frames: [
{
src: 'common/landscape1.jpg',
width: '250px',
height: '250px',
left: '150px',
top: '50px',
},
{
src: 'common/landscape2.jpg',
width: '300px',
height: '300px',
left: '150px',
top: '100px',
},
{