Fork me on GitHub

[小程序]-wx.createAnimation创建动画

近在写一个直播的小程序,需要一个点击点赞屏幕飘动的动画效果,使用到wx.createAnimation,感谢黄军福千达(ecardh8)老哥给予的支持,特此感谢

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//点赞动画效果
clickLike: function () {
var x = -100, y = -400;
var rand = parseInt(Math.random() * (x - y + 1) + y), animationData = {};
this.animation = wx.createAnimation({ duration: 2000, timingFunction: 'ease-in-out' });
this.animation.translateY(-600).opacity(0).translateX(rand).step();
animationData[animationindex] = this.animation.export();
this.setData({ animationData: animationData });
animationindex == this.data.likeimg.length ? animationindex = 0 : animationindex = animationindex + 1;
},
//点赞动画清除
transitionend: function (t) {
this.clearanimation = wx.createAnimation({ duration: 0 });
this.clearanimation.translateY(0).opacity(1).translateX(0).step();
var dataindex = t.target.dataset.index ? t.target.dataset.index : 0;
var animationData = {};
animationData[dataindex] = this.clearanimation.export();
this.setData({ animationData: animationData });
},
支持作者