微信小程序触摸滑动事件

 代码主要为了解决微信小程序胶囊按住拖到下面一定距离还有背景色,要实现这个效果

<view class='btn'  bindtouchstart='touchStart' bindtouchmove='touchMove' bindtouchend='touchEnd' bindtouchcancel="touchcancel">
OK
</view>
 data: {
    touchS : [0,0],
    touchE : [0,0]
  },

  touchStart: function(e){
    // console.log(e.touches[0].pageX)
    let sx = e.touches[0].pageX
    let sy = e.touches[0].pageY
    this.data.touchS = [sx,sy]
  },
  touchMove: function(e){
    let sx = e.touches[0].pageX;
    let sy = e.touches[0].pageY;
    this.data.touchE = [sx, sy]
  },
  touchEnd: function(e){
    let start = this.data.touchS
    let end = this.data.touchE
    console.log(start)
    console.log(end)
    if(start[0] < end[0] - 50){
      console.log('右滑')
    }else if(start[0] > end[0] + 50){
      console.log('左滑')
    }else{
      console.log('静止')
    },
    touchcancel:function(e){
      this.setData({
        touchse:'rgba(255, 255, 255, 0)',
      });
    },
  },

 

 


版权声明:本文为qq_29058883原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。