Zepto的SwipeUp 在 android 和微信 的解决方案

Zepto的SwipeUp 在 android 和微信 的解决方案

时间:2016-04-19 22:20:09html

做者:zhongxiaandroid


问题解决方案:

Q:为何swipeUp和swipeDown在手机测试不成功??git

A: 把这段代码添加到 zepto.min.js 的最上面github

document.addEventListener('touchmove', function (event) { event.preventDefault(); }, false);

这段代码仍是有问题:   内容太长出现滚动条以后, 没有办法滚动浏览器

作公司的一个手机站,发现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()
      })

虽说这点代码, 可是这段代码要放在什么地方呢? 测试

加载 自执行函数里面的  $(window).on 的绑定事件上spa

NewImage

 

DEMO: http://zhongxia245.github.io/demo/ZeptoTouch/index.htmlcode

能够在微信扫码,打开试一下,Android 的浏览器一样能够试一下

相关文章
相关标签/搜索