<image src="" animation="{{ animation }}">
animation 属性可应用于 view 、image 等组件;
startAnimation() {
let animation = wx.creatAnimation({
duration: 1200,
timingFunction: 'linear',
});
this.data.timer = setInterval({
let next = true;
if(next) {
animation.translate(110, 0).step()
}else {
animation.translate(0, 0).step()
}
next = !next
this.setDate({
animationData: animation.export()
})
}, 1200)
},
onShow() {
this.startAnimation()
},
clearAnimation() {
clearInterval(this.data.timer)
},
onHide() {
this.clearAnimation()
}
wx.createAnimation() 有完整代码;