I am developing an online painter and I need to know in which part of the canvas * -a * (and it is not full screen) to be the cursor (and I can't find the size of the canvas :( ).
Ps Here is an illustration to make it clearer:
I am developing an online painter and I need to know in which part of the canvas * -a * (and it is not full screen) to be the cursor (and I can't find the size of the canvas :( ).
Ps Here is an illustration to make it clearer:
In general, Flash for such things is much better than Javascript. Pruflnik
So:
function position(event) { var x = y = 0; if (document.attachEvent != null) { x = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); y = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); } else if (!document.attachEvent && document.addEventListener) { x = event.clientX + scrollX; y = event.clientY + scrollY; } else {} return {x: x,y: y}; }
Source: https://ru.stackoverflow.com/questions/145772/
All Articles