在 fabricjs 中如何在 fabric.controlsUtils actionHandler 中赋予多个函数?

问题描述 投票:0回答:1

在 fabricjs 中,我需要在一个 fabric.controlsUtils 中提供两个 actionHandler 函数

objectControls.br = new fabric.Control({
    x: 0.5,
    y: 0.5,
    cursorStyleHandler: scaleStyleHandler,
    actionHandler:(()=>{widthchangeobjscale , scalingEqually}),     >>>>>>>> not working
  });
javascript reactjs canvas fabricjs
1个回答
0
投票

你需要把原来的

actionHandler
包起来。试试这个:

function customFunc() {
  console.log("called");
}

const objControls = fabric.Object.prototype.controls;
const originalActionHandler = objControls.br.actionHandler;
objControls.br.actionHandler = (...args) => {
  customFunc();
  return originalActionHandler(...args);
};

工作示例:https://codesandbox.io/s/fabricjs-wrap-control-action-handler-u50h32?file=/src/index.ts:329-379

© www.soinside.com 2019 - 2024. All rights reserved.