微信小程序金刚位置动画

//金刚位动画
    this.animations=wx.createAnimation({
      duration: 500,
      timingFunction: 'linear',
    })
translate: function (val) {
    let moveNumber=Math.ceil(this.data.indexBottomData.length/2-5)
    this.nowMoveWidth=!val?this.nowMoveWidth-this.moveWidth:this.nowMoveWidth+this.moveWidth
    let nowPercent=Math.abs(this.nowMoveWidth/this.moveWidth)
    if((moveNumber+1)>nowPercent && this.nowMoveWidth<1){
      this.animations.translateX(this.nowMoveWidth+'px').step()
      this.setData({animation: this.animations.export()})
      this.isTouch=false;
    }
    if(this.nowMoveWidth<-moveNumber*this.moveWidth && this.isTouch){
      this.nowMoveWidth=-moveNumber*this.moveWidth
    }
    if(this.nowMoveWidth>0 && this.isTouch){
      this.nowMoveWidth=0
    }
    this.setData({
      goldPercent:Math.abs(this.nowMoveWidth/this.moveWidth)/moveNumber
    })
  },
  touchStart(e){
    this.isTouch=true
    this.touchDot = e.touches[0].pageX; // 获取触摸时的原点
  },
  touchMove(e){
      let touchMove = e.touches[0].pageX;
      // 向左滑动  
      if (touchMove - this.touchDot <= -30 && this.isTouch) {
        //这里执行要操作的任务
        this.translate(0)
      }
      // 向右滑动 
      if (touchMove - this.touchDot >= 40 && this.isTouch) {
        //这里执行要操作的任务
        this.translate(1)
      }
  },
posted @ 2021-07-29 15:57  renhj  阅读(365)  评论(0)    收藏  举报