javascript - FabricJS - Better solution to centering object on cursor when selected? -
i selectable objects snap center mouse cursor on click. modification allowed user in case moving object, no scaling, rotating, etc. updating position of object on mousedown or selected update position until moving event fired, object snap original position , begin following mouse. rect.on('moving', movehandler); function movehandler(evt) { var mousepnt = $canvas.getpointer(evt.e); rect.set({ left:mousepnt.x - rect.width*0.5 , top:mousepnt.y - rect.height*0.5}); this.setcoords(); } this i've come center selectable rectangle on cursor, i'm it's firing 2 movement events. there way override original positioning. or should instead write own mousedown , mouseup , , moving listeners mimic default dragging behavior? you solution fine if no rotating or scaling involved. you not executing more necessary if not .setcoords during movement optional since called on mouseup when translation finished. if want take mousedown approach, changing position