【问题标题】:How to enable & handle "tap" event on fabricjs on mobile device?如何在移动设备上的 fabricjs 上启用和处理“点击”事件?
【发布时间】:2019-12-11 21:20:39
【问题描述】:



我想在移动设备上使用fabricjs 处理事件点击。实现它的正确方法是什么?

目前,我看到在 fabricjs 源代码中实现“tap”事件。如果我想处理那个事件,我需要更改 fabricjs 源代码:

if (typeof eventjs !== 'undefined' && eventjsFunctor in eventjs) {
    eventjs[eventjsFunctor](canvasElement, 'gesture', this._onGesture);
    eventjs[eventjsFunctor](canvasElement, 'drag', this._onDrag);
    eventjs[eventjsFunctor](canvasElement, 'orientation', this._onOrientationChange);
    eventjs[eventjsFunctor](canvasElement, 'shake', this._onShake);
    eventjs[eventjsFunctor](canvasElement, 'longpress', this._onLongPress);
    eventjs[eventjsFunctor](canvasElement, 'tap', this._onLongPress);
  }

添加最后一行:

eventjs[eventjsFunctor](canvasElement, 'tap', this._onLongPress);

现在我可以通过“长按”事件来捕捉点击事件。

this.canvas.on({'touch:longpress': function(e) {
        console.log("touch:longpress + tap");
    });

我的问题是有另一种很好的方法来处理fabricjs 上的“tap”事件而无需修改fabricjs 源代码并且可以通过监听“touch:tap”事件名称来处理“tap”事件?

谢谢,

【问题讨论】:

    标签: html5-canvas fabricjs fabricjs2


    【解决方案1】:

    您可以使用

    将事件添加到uppercanvas
    eventjs.add( canvas.upperCanvasEl, 'tap', onTap);
    eventjs.remove( canvas.upperCanvasEl, 'tap', onTap);
    
    function onTap(e) {
      console.log("tap");
    })
    

    【讨论】:

      猜你喜欢
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      相关资源
      最近更新 更多