Hello, I would suggest a different approach to this functionality , so that it is more stable, since it does not add elements to the DOM, we can use it on as many objects as we like, we do not need to hide and show custom corner buttons and corner buttons are visible every time an object is active (fabricjs native functions).
- I am going to override the prototype of the _drawControl object to add my own angular images.
- And redefine the canvas prototype _setCornerCursor to change the real-time mouse pointer where the corner ended.
- I made a live fiddle here: https://jsfiddle.net/tornado1979/j987gb6f/
A. First of all, I need to preload custom angle images, so whenever we click on an object, there will be no delay (I used random images only for shows).
var ctrlImages = new Array() function preload() { for (i = 0; i < preload.arguments.length; i++) { ctrlImages[i] = new Image(); ctrlImages[i].src = preload.arguments[i]; } } preload( "https://cdn1.iconfinder.com/data/icons/ui-color/512/Untitled-12-128.png", "https://cdn2.iconfinder.com/data/icons/social-messaging-productivity-1/128/sync-16.png", "https://cdn2.iconfinder.com/data/icons/social-messaging-productivity-1/128/write-compose-16.png",
B. I redefine _drawcontrol (I only show a fragment that changes angles):
switch (control) { case 'tl': SelectedIconImage.src = ctrlImages[1].src;//our custom img break; case 'tr': if (flipiX && !flipiY) { n='2'; } if (!flipiX && flipiY) { n='3'; } if (flipiX && flipiY) { n='4'; } SelectedIconImage.src = ctrlImages[0].src;//our custom img break; case 'mt': break; case 'bl': if (flipiY) { n='2'; } SelectedIconImage.src = ctrlImages[3].src;//our custom img break; case 'br': if (flipiX || flipiY) { n='2'; } if (flipiX && flipiY) { n=''; } SelectedIconImage.src = ctrlImages[2].src;//our custom img break; case 'mb': break; case 'ml': break; case 'mr': break; default: ctx[methodName](left, top, sizeX, sizeY); break; }
C. Override _setCornerCursor to change the cursor when the mouse is over the corner of an object. Inside the function I use the setCursor () function, which actually takes a string as a parameter, so we can look here for cursors: https://www.w3.org/TR/css3-ui/#cursor
fabric.Canvas.prototype._setCornerCursor = function(corner, target) { //for top left corner if(corner == "tl"){ this.setCursor(this.rotationCursor); return false; //for top right corner }else if(corner == "tr"){ this.setCursor('pointer'); return false; //for bottom left corner }else if(corner == "bl"){ this.setCursor('help'); return false; //for bottom right corner }else if(corner == "br"){ this.setCursor('copy'); return false; } };
D. Finally, on the mouse: down I check the angle and add the functionality of canvas.on ('mouse: down', function (e) {..}

Hope helps, good luck.