Hi, guys i am working on a way to draw with your mouse with Canvas. This is how far i am:
function drawdraw(){
test = document.getElementById('test');
ctx = test.getContext('2d');
window.addEventListener("mousemove", drawing,false);
}
function drawing(e){
ctx.clearRect(0,0,500,200);
var xPos = e.pageX-test.offsetLeft;
var yPos = e.pageY-test.offsetTop;
ctx.fillRect(xPos, yPos,30,30);
}
window.addEventListener("load", drawdraw,false);
My current problem is that I do not have the right cursor coordinates. I tried e.clientX , e.clientX and the example above.
I want to be able to move my canvas dynamicly, and I want the coordinates of the mouse to be 0,0 at top left of the canvas, and 500,200 at the bottom right of the canvas. In other words I just want my coordinates to be within the canvas, and not coordinates of the page. Anyone? :)
Btw. I am interested in a javascript solution, so if I can, I want to avoid jQuery.