收藏
回答

小程序实现左滑弹出菜单,右滑隐藏菜单。在工具仿真可用,但是在真机上右滑功能失效

框架类型 问题类型 终端类型 操作系统 微信版本 基础库版本
小程序 Bug 微信iOS客户端 Android 6.6.6 2.0.8
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,
         })
         //that.move();
       }
     }
   }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,
           })
           //that.move();
         }
       }
     }
   }   
 },


回答关注问题邀请回答
收藏

1 个回答

  • HS
    HS
    2018-05-19

    类似这种问题,在真机上测试时,可以打印 log,看看坐标和样式计算是不是正确的。

    2018-05-19
    有用
    回复
登录 后发表内容