Get mouse position in fabric.js while moving

I'd like to get the mouse position while moving.

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

{
    console.log(e.e.clientX,e.e.clientY);
}
canvas 
{
  border: 1px solid red;
}
<canvas id="c1" width="300" height="300"></canvas>

<script src="https://unpkg.com/[email protected]/dist/fabric.js"></script> 

This gets me the position of the mouse when I click. How do I get mouse position while moving the mouse?

Upvotes: 1

Views: 106

Answers (1)

tao
tao

Reputation: 90277

A quick peek at Canvas docs suggest replacing mouse:up with mouse:move should be what you're after.

See it working:

const canvas = new fabric.Canvas('c1');

const getMouse = ({ e }) => {
  console.log(e.clientX, e.clientY);
}

canvas.on('mouse:move', getMouse);
canvas { border: 1px solid red; }
<canvas id="c1" width="300" height="300"></canvas>
<script src="https://unpkg.com/[email protected]/dist/fabric.js"></script>

Upvotes: 1

Related Questions