StAR_161 StAR_161 - 2 years ago 341
jQuery Question

How do I get mouse coordinates on Fabric.js?

I'm trying to read the X coordinate of a mouse click on Fabric.js.

Here is my code. The console logs

every time.

var canvas = new fabric.Canvas('c1');
canvas.on('mouse:down', function(e){

function getMouse(e) {

Answer Source

The best fix is this method


function getMouseCoords(event)
  var pointer = canvas.getPointer(event.e);
  var posX = pointer.x;
  var posY = pointer.y;
  console.log(posX+", "+posY);    // Log to console
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download