[转] zepto的各种坑

1、编译zepto。模块之前可能有依赖关系,整体顺序参考下面这个即可:

MODULES="zepto event ajax form ie detect fx fx_methods assets data deferred callbacks selector touch gesture stack ios3" npm run-script dist

2、支持requirejs。在

window.Zepto = Zepto
'$' in window || (window.$ = Zepto) 

后增加如下代码,以便支持requirejs

if ( typeof define === "function" && define.amd ) { define( "zepto", [], function () { return Zepto; } ); } 

3、加入如下代码,以支持微信等部分浏览器的滑动

if (touch.x2 && Math.abs(touch.x1 - touch.x2) > 10){ e.preventDefault() } 

在如下方法中增加

.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) if (touch.x2 && Math.abs(touch.x1 - touch.x2) > 10){ e.preventDefault() } }) 

详情见:https://github.com/jnotnull/zepto

4、因IOS在第三方输入法下不支持onkeyup事件,所以需要使用oninput进行代替onkeyup事件

$("#user-name")[0].oninput = function() { that.checkusername(); }; 

5、使用fastclick代替zepto的tap事件,防止出现穿透问题。

猜你喜欢

转载自www.cnblogs.com/chris-oil/p/8996483.html