html5-canvas - 如何在移动设备上的 fabricjs 上启用和处理“点击”事件?
问题描述
我想在移动设备上使用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);
现在我可以通过“longpress”事件来捕捉点击事件。
this.canvas.on({'touch:longpress': function(e) {
console.log("touch:longpress + tap");
});
我的问题是有另一种很好的方法来处理fabricjs上的'tap'事件而无需修改fabricjs源代码并且可以通过听“touch:tap”事件名称来处理'tap'事件?
谢谢,
解决方案
您可以使用将事件添加到uppercanvas
eventjs.add( canvas.upperCanvasEl, 'tap', onTap);
eventjs.remove( canvas.upperCanvasEl, 'tap', onTap);
function onTap(e) {
console.log("tap");
})
推荐阅读
- python - 无法正确存储最佳神经元列表
- javascript - 为什么评论没有立即出现在我的 React 应用项目中?
- regex - Powershell转换字符串不起作用
- facebook - 从 Facebook 应用程序访问用户 Facebook Messenger 收件箱
- r - 如何删除特定列中具有 NA 的行,但前提是它们在另一列中有重复?
- pandas - ValueError:给定的列不是数据框的列
- xamarin - 首次访问后无法导航回 Xamaran Shell 页面
- sql - Laravel,显示大数据的查询很慢
- java - okhhtp3 mockserver java.lang.NoClassDefFoundError: okhttp3/internal/concurrent/TaskRunner$RealBackend
- node.js - 带有 API 网关的 AWS ECS 中微服务的基于路径的路由