How i can get coords of a rendered canvas element? I need them to apply clearRect, fillRect etc to its area.
I get the canvas:
//html
<div><canvas id="canvas_id">some useless text..</canvas></div>
//javascript
var ctx = document.getElementById('canvas_id').getContext('2d');
Then? there is a way to get top left x, top left y, width and height of this?
@update after moonshadow's answer:
thx for answer, i know that operations are relative to the canvas, but i asked the question because i don't explain myself this behaviour: i have done a test file with a canvas object (http://avastreg.ilbello.com/canvas/test.html).
Here i've put a form in which dimensions for clearRect can be sended through the form. When you trigger mouseover on the canvas (NEWS), it applies clearRect with that coords. On mouseout he refills.
Starting value are :
x = 0, y = 0, w = 200, h = 200
. Notice that doesn't work.
Then try something like
x: -10000, y: -10000, w: 50000000, h: 50000000
=> it seems a joke but this works!
With other values it goes partially cleared. Why this happens?