|
@@ -63,20 +63,27 @@ Page({
|
|
|
flag: 0,
|
|
|
lastX: 0,
|
|
|
lastY: 0
|
|
|
- }
|
|
|
+ },
|
|
|
+ animationData: {},
|
|
|
+ currentIndex: 0,
|
|
|
+ isAnimating: false
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady() {
|
|
|
-
|
|
|
+ this.initAnimations();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.startAnimationLoop();
|
|
|
+ }, 500);
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -169,5 +176,72 @@ Page({
|
|
|
touchData
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
+ initAnimations: function() {
|
|
|
+ const list = this.data.list;
|
|
|
+ list.forEach((item, index) => {
|
|
|
+ this.createAnimation(index);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ createAnimation: function(index) {
|
|
|
+ const animation = wx.createAnimation({
|
|
|
+ duration: 1000, // 动画持续时间
|
|
|
+ timingFunction: 'ease', // 动画效果
|
|
|
+ });
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ ['animationData[' + index + ']']: animation.export(),
|
|
|
+ });
|
|
|
+ },
|
|
|
+ startAnimationLoop: function() {
|
|
|
+ const list = this.data.list;
|
|
|
+ const currentIndex = this.data.currentIndex;
|
|
|
+
|
|
|
+ if (currentIndex < list.length) {
|
|
|
+ if (this.data.isAnimating) return;
|
|
|
+ this.setData({
|
|
|
+ isAnimating: true
|
|
|
+ })
|
|
|
+ // 获取当前索引的动画对象
|
|
|
+ const animation = wx.createAnimation({
|
|
|
+ duration: 1000,
|
|
|
+ timingFunction: 'linear',
|
|
|
+ });
|
|
|
+
|
|
|
+ // 放大动画
|
|
|
+ animation.scale(1.2, 1.2).step();
|
|
|
+
|
|
|
+ // 更新动画数据
|
|
|
+ this.setData({
|
|
|
+ ['animationData[' + currentIndex + ']']: animation.export(),
|
|
|
+ isAnimating: this.data.isAnimating
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置动画结束后回调
|
|
|
+ setTimeout(() => {
|
|
|
+ // 恢复到原始大小
|
|
|
+ const restoreAnimation = wx.createAnimation({
|
|
|
+ duration: 1000,
|
|
|
+ timingFunction: 'linear',
|
|
|
+ });
|
|
|
+ restoreAnimation.scale(1, 1).step();
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ ['animationData[' + currentIndex + ']']: restoreAnimation.export(),
|
|
|
+ isAnimating: false
|
|
|
+ });
|
|
|
+
|
|
|
+ // 动画结束后,索引递增,如果到达列表末尾,则重置为0
|
|
|
+ this.setData({
|
|
|
+ currentIndex: (currentIndex + 1) % list.length,
|
|
|
+ });
|
|
|
+ if ((currentIndex + 1) % list.length == 0 && currentIndex != 0) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.startAnimationLoop();
|
|
|
+ }, 2000);
|
|
|
+ } else {
|
|
|
+ this.startAnimationLoop();
|
|
|
+ }
|
|
|
+ }, 1500);
|
|
|
+ }
|
|
|
+ },
|
|
|
})
|