白月
白月
  • 发布:2021-08-18 10:47
  • 更新:2022-06-16 17:55
  • 阅读:849

动画用setInterval去执行,但是只能执行一次

分类:uni-app

直接上代码。动画的目的是,让两个view进行一个接着一个的摇摆,并且如此循环。但是只会执行一次。
我也试过在 setInterval 中进行uni.createAnimation动画,也不行,也是只能一次,在H5预览中是可以的,微信小程序和APP是不行的。
然后我log动画执行动作,却是可以执行的。

onShow: function(){  
            let timer;  

            var animation = uni.createAnimation({  
              duration: 280,  
                timingFunction: 'linear',  
            })  

            this.animation = animation  
            this.rotateAndScale();  
            setTimeout(function() {  
                 this.rotateAndScale2();  
            }.bind(this), 3000);  

            timer = setInterval(()=>{    
                this.animation = animation  
                    this.rotateAndScale();  
                    setTimeout(function() {  
                          this.rotateAndScale2();  
                        }.bind(this), 3000);  

            },7000)  

          },
rotateAndScale: function () {  
                  // 旋转同时放大  
                  console.log('执动画1')  
                  this.animation.rotate(15,15).step()  
                   this.animation.rotate(-15,-15).step()  
                   this.animation.rotate(10,10).step()  
                   this.animation.rotate(-10,-10).step()  
                   this.animation.rotate(5,5).step()  
                   this.animation.rotate(-5,-5).step()  
                   this.animation.rotate(0,0).step()  
                   this.animationData1 = this.animation.export()  
                },  
                rotateAndScale2: function () {  
                      // 旋转同时放大  
                      console.log('执动画2')  
                      this.animation.rotate(15,15).step()  
                       this.animation.rotate(-15,-15).step()  
                       this.animation.rotate(10,10).step()  
                       this.animation.rotate(-10,-10).step()  
                       this.animation.rotate(5,5).step()  
                       this.animation.rotate(-5,-5).step()  
                       this.animation.rotate(0,0).step()  
                       this.animationData2 = this.animation.export()  
                    },
2021-08-18 10:47 负责人:无 分享
已邀请:
f***@youmix.cn

f***@youmix.cn

顶起来,居然没人回答

白月

白月 (作者)

这个解决了,需要再执行一次

  • Easion

    请问怎么解决的

    2022-09-28 10:22

要回复问题请先登录注册