I am using fabricjs
in Angular 8 and on mouse wheel event, I want to zoom the canvas. But, when the event is triggered, I got the error about the function, canvas.getZoom()
is undefined
. I have searched but, I didn't get anything related to this issue. My other functionality in the fabricjs
is working, but this isn't.
Here is my code :
this.canvas.on('mouse:wheel', function(opt) {
var delta = opt.e.deltaY;
console.log("delta",delta)
var zoom = this.canvas.getZoom();
console.log("zoom",zoom)
zoom = zoom + delta/200;
if (zoom > 20) zoom = 20;
if (zoom < 0.01) zoom = 0.01;
this.canvas.setZoom(zoom);
opt.e.preventDefault();
opt.e.stopPropagation();
})
It prints on the console with the value of delta, but after this.canvas.getZoom()
fires, it throws error.