Course recommendation:
Canvas translate() method
Definition and usage
translate()
Note:method to remap the (0,0) position on the canvas after translate(). When you call methods like fillRect() x and similar methods, the value will be added to y on the coordinate value.

Example
Draw a rectangle at position (10,10), setting the new (0,0) position to (70,70). Draw the new rectangle again (note that the rectangle now starts at position (80,80)):
JavaScript:
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.fillRect(10,10,100,50); ctx.translate(70,70); ctx.fillRect(10,10,100,50);
Syntax
context.translate(x,y);
Parameter value
Parameter | Description |
---|---|
x | The value added to the horizontal coordinate (x). |
y | The value added to the vertical coordinate (y). |
Browser Support
The numbers in the table indicate the first browser version that fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.