fabric.js touchmove和drag冲突 拖拽和滚动条冲突 allowTouchScrolling不生效

fabric.js version:5.4.0 目前不太清楚其他版本支不支持 应该5.4之前都可以 其他版本请自行测试
前提:
需要开启允许触摸滚动
new fabric.Canvas(canvasEle, {
allowTouchScrolling: true
})

解决代码:

(function(){
  var defaultOnTouchStartHandler = fabric.Canvas.prototype._onTouchStart;
  fabric.util.object.extend(fabric.Canvas.prototype, { 
    _onTouchStart: function(e) { 
      var target = this.findTarget(e); 
      // if allowTouchScrolling is enabled, no object was at the
      // the touch position and we're not in drawing mode, then 
      // let the event skip the fabricjs canvas and do default
      // behavior
      if (this.allowTouchScrolling && !target && !this.isDrawingMode) { 
        // returning here should allow the event to propagate and be handled
        // normally by the browser
        return; 
      } 

      // otherwise call the default behavior
      defaultOnTouchStartHandler.call(this, e); 
    } 
  });
})();

原理是监听了onTouchStart方法 如果开启了允许触摸滚动(allowTouchScrolling)且不处于绘画模式(isDrawingMode) 就可以滚动

初始化时加入 (function(){})是JQ初始化的方法,vue在created加入即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值