[Turn] Various pits of zepto

1. Compile zepto. There may be dependencies before modules, and the overall order can be referred to as follows:

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

2. Support requirejs. exist

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

Then add the following code to support requirejs

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

3. Add the following code to support the sliding of some browsers such as WeChat

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

add in the following method

.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() } }) 

For details, see: https://github.com/jnotnull/zepto

4. Because IOS does not support the onkeyup event under the third-party input method, it is necessary to use oninput instead of the onkeyup event

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

5. Use fastclick instead of zepto's tap event to prevent penetration problems.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325355317&siteId=291194637
Recommended