本文共 773 字,大约阅读时间需要 2 分钟。
代码主要为了解决微信小程序胶囊按住拖到下面一定距离还有背景色,要实现这个效果
OK
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)', }); }, },
转载地址:http://zdtin.baihongyu.com/