javascript - 在 fabric js 中使用事件处理程序 (.on) 将数据发送到函数

标签 javascript fabricjs

正如标题所解释的,我正在尝试通过事件处理程序将数据发送到函数。

我试过以下方法:

canvas.on("mouse:wheel",{name:"spin"}, constructSpin);
function constructSpin(e){
console.log(e.data.name);
}

遗憾的是这不起作用:(

有什么方法可以使用事件处理程序将数据发送到函数吗?

注意:我在 fabric 文档中找到了这个:

on(eventName, handler) → {Self}

所以看起来没有数据在 build 中!

最佳答案

如果您希望在 mouse:wheel 事件上传递一些自定义数据,您应该按以下方式构造和调用 constructSpin 函数:

canvas.on("mouse:wheel", function(e) {
   constructSpin(e, { name: "spin" });
});

function constructSpin(event, data) {
   console.log(data.name);
}

关于javascript - 在 fabric js 中使用事件处理程序 (.on) 将数据发送到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45907866/

相关文章:

javascript - SVG 与 CANVAS(Snap.svg 与 FabricJS)

javascript - 使用 Javascript js 提交后清除 HTML 表单

c# - cometd 性能问题

javascript - 删除d3 js中的项目

html5-canvas - Fabric JS : Snapping guidelines not correctly positioned when zoomed

javascript - 为圆形对象fabricjs添加边框

javascript - 获取触摸拖动布料后的x和y JS

Javascript计时事件、倒计时和显示

javascript - Firebase 实时数据库是否有任何 "lifecycle"事件?

webgl - 使用 FabricJS 过滤器和自定义控件扭曲图像,通过从中心拖动角控制点调整图像大小