小程序动画wx.createAnimation

首先上官网

将动画封装到一个函数,在需要的时候调用,也可以在满足一定条件时重复调用.

<view animation="{{animationData}}" ></view>
onLoad: function(){
    this.newInfor();
}



newInfor(){
      var animation = wx.createAnimation({
        duration: 1000,
        timingFunction: 'linear',
      })

      this.animation = animation

      animation.translate(150).step()

      this.setData({
        animationData: animation.export()
      })

      setTimeout(function () {
        animation.translate(-150).step()
        this.setData({
          animationData: animation.export()
        })
      }.bind(this), 2000)
    }