FabricJS, change control button image when hover

Viewed 27

I am using a custom rotation icon that shows when I select objects, defined as I create the canvas.

function renderRotationIcon(ctx, left, top, styleOverride, fabricObject) {
  //@ts-ignore
  let size = this.cornerSize
  ctx.save()
  ctx.translate(left, top)
  //@ts-ignore
  ctx.rotate(fabric.util.degreesToRadians(fabricObject.angle))
  ctx.drawImage(img, -size / 2, -size / 2, size, size)
  ctx.restore()
}

However, I would like to change the image img when the user hovers the rotation icon.

I tried this when defining img

img.onmouseover = () => {
  img.src = "LibraryHoverTrans.png"
}

As expected, this didn't work, as I suspect that something more specific to fabricJS is needed. I tried searching for a related solution.

0 Answers
Related