I am trying to perform a special action whenever the user double clicks any object located inside the canvas. I have read the docs and not found any mouse:dblclick
-like event in the documentation. I tried doing something like:
fabric.util.addListener(fabric.document, 'dblclick', callback);
Which does trigger the dblclick event but does not give specific information about the actual object that is being clicked on the canvas.
Any ideas of the most FabricJS-y way of doing this?
Here is a quick and easy way to add a double click event handler to Fabric JS -
Include following code snippet to your html file. Just ensure this is loaded after the main fabric.js library
Then add this code to listen a double click event:
To get information about the actual object that is being clicked on the canvas, use following method -
eg.
I'm using this workaround:
The Correct way to add custom events to Fabric.js
or use fabric.ext
The more elegant way is to override fabric.Canvas._initEventListeners to add the dblclick support
I've also developed a library to implement more events missed in fabricjs : https://github.com/mazong1123/fabric.ext
This is similar to @LeoCreer's answer but actually gets access to the targeted object