In this solution in javascript
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
In this solution in javascript
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
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.
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