做公司的一个手机站,发现zepto的touch.js在安卓上的兼容性有bug,主要是在微信上无法触发swipe*事件,而且这个 bug 作者不愿意修,理由是:我特么没有安卓设备。发生这种bug的原因大概是安卓设备上

网上找到了一个大神的初步解决方案:在touch.js中加一段代码:

.on('touchmove MSPointerMove pointermove', function(e){
        if((_isPointerType = isPointerEventType(e, 'move')) &&
          !isPrimaryTouch(e)) return
        firstTouch = _isPointerType ? e : e.touches[0]
        cancelLongTap()
        touch.x2 = firstTouch.pageX
        touch.y2 = firstTouch.pageY

        deltaX += Math.abs(touch.x1 - touch.x2)
        deltaY += Math.abs(touch.y1 - touch.y2)

        /**
         * 修复 android 4.4 swipe 事件
         * https://github.com/madrobby/zepto/issues/315#issuecomment-8386027
         */
        if (touch.x2 && Math.abs(touch.x1 - touch.x2) > 10)
            e.preventDefault()
      })

点击原因及进一步fix  

 posted on 2015-10-24 16:27  vincent2d  阅读(593)  评论(0编辑  收藏  举报