• [转] 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事件,防止出现穿透问题。

  • 相关阅读:
    P6585 中子衰变
    [APIO2020]有趣的旅途
    CF1354F Summoning Minions
    CF1361C Johnny and Megan's Necklace
    CF1368E Ski Accidents
    CF1458C Latin Square
    CF1368F Lamps on a Circle
    用户和组的管理
    Windows命令
    1
  • 原文地址:https://www.cnblogs.com/chris-oil/p/8996483.html
Copyright © 2020-2023  润新知