微信小程序:左滑右滑

wxml

<view
	bindtouchstart='touchStart'
	bindtouchend="touchEnd"
	>

js

Page({
     
	data: {
     
	    touchStartX: 0,
	    touchStartY: 0,
	    touchEndX: 0,
	    touchEndY: 0
	},
    touchStart(e) {
     
      this.setData({
     
        touchStartX: e.changedTouches[0].clientX,
        touchStartY: e.changedTouches[0].clientY
      });
    },
    touchEnd(e) {
     
      this.setData({
     
        touchEndX: e.changedTouches[0].clientX,
        touchEndY: e.changedTouches[0].clientY
      });
      this.touchMove()
    },
    touchMove() {
     
      var startX = this.data.touchStartX
      var startY = this.data.touchStartY
      var endX = this.data.touchEndX
      var endY = this.data.touchEndY
      if (endX - startX > 50 && Math.abs(endY - startY) < 50) {
     
      	console.log('右划了====')
      } else if (endX - startX < -50 && Math.abs(endY - startY) < 50) {
     
        console.log('左划了====')
      }
    }
})

你可能感兴趣的:(微信小程序,小程序)