touchstart: function (e) {
var that = this ;
that.setData({
touchs: e.touches[0].pageX,
touche: e.touches[0].pageX,
})
},
touchmove: function (e) {
var that = this ;
that.setData({
touche: e.touches[0].pageX,
})
let offset = that.data.touche - that.data.touchs;
if (offset > 0){
if (that.data.open){
that.setData({
style: 'transform: translateX(' + that.data.windowwidth * 0.7 + 'px)' ,
})
} else {
if (offset >= that.data.windowwidth * 0.7)
offset = that.data.windowwidth * 0.7;
that.setData({
style: 'transform: translateX(' + offset + 'px)' ,
})
}
} else {
if (that.data.open){
offset = that.data.touchs - that.data.touche;
if (offset >= that.data.windowwidth * 0.7)
offset = that.data.windowwidth * 0.7;
var width = that.data.windowwidth*0.7 - offset
that.setData({
style: 'transform: translateX(' + width * 0.7 + 'px)' ,
})
} else {
that.setData({
style: 'transform: translateX(' + 0 + 'px)' ,
})
}
}
},
touchend: function (e) {
var that = this ;
that.setData({
touche: e.changedTouches[0].pageX,
})
let offset = that.data.touche - that.data.touchs;
if (offset > 0){
if (offset < that.data.windowwidth * 0.3){
that.setData({
style: 'transform: translateX(' + 0 + 'px)' ,
})
} else {
if (offset >= that.data.windowwidth * 0.3){
that.setData({
style: 'transform: translateX(' + that.data.windowwidth * 0.70 + 'px)' ,
open: true ,
})
}
}
} else {
if (that.data.open){
offset = that.data.touchs - that.data.touche;
if (offset < that.data.windowwidth * 0.3) {
that.setData({
style: 'transform: translateX(' + that.data.windowwidth * 0.7 + 'px)' ,
})
} else {
if (offset >= that.data.windowwidth * 0.3) {
that.setData({
style: 'transform: translateX(' + 0 + 'px)' ,
open: false ,
})
}
}
}
}
},
|
类似这种问题,在真机上测试时,可以打印 log,看看坐标和样式计算是不是正确的。