pixel-editor/js/_getCursorPosition.js

21 lines
535 B
JavaScript

//get cursor position relative to canvas
function getCursorPosition(e) {
var x;
var y;
if (e.pageX != undefined && e.pageY != undefined) {
x = e.pageX;
y = e.pageY;
console.log("passato di qui");
}
else {
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
x -= canvas.offsetLeft;
y -= canvas.offsetTop;
return [Math.round(x), Math.round(y)];
}