1

In this solution in javascript

JavaScript while mousedown

I can get the mouse location when it's first pressed and first clicked, but how can I get the location while its being pressed down?

Thanks

Community
  • 1
  • 1
omega
  • 40,311
  • 81
  • 251
  • 474

2 Answers2

1

You can track every movement mouse, like this Track mouse movement and add logic for tracking only if before was mouse click down a stop when mouse was click up.

Community
  • 1
  • 1
Matej Marconak
  • 1,365
  • 3
  • 20
  • 25
0

You can get any instance of mouse coordinate inside <canvas>. In this case, planting other tags inside <canvas> limited and could be done only via {position: absolute}. Code example:

canvas.addEventListener('mousemove', getPoint);
function getPoint(e){
const [x, y] = [e.offsetX, e.offsetY]; 
const offsetX = document.getElementById('offsetX');
offsetX.textContent = `Offset X: ${x}`;
const offsetY = document.getElementById('offsetY');
offsetY.textContent = `Offset Y: ${y}`;
};

Working example: http://codepen.io/462960/pen/RpVJwa

Seemax
  • 121
  • 12