HTML canvas rotate() method
Example
Rotate the rectangle by 20 degrees:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rotate(20*Math.PI/180);
ctx.fillRect(50,20,100,50);
Try it »
Browser support





Internet Explorer 9, Firefox, Opera, Chrome and Safari support the rotate() method.
**Note:** Internet Explorer 8 and earlier versions do not support
Definition and Usage
The rotate() method rotates the current drawing.
**Note:** The rotation only affects the drawing done after the rotation.
| JavaScript syntax: | context.rotate(angle); |
|---|
Parameter value
| Parameters | Description |
|---|---|
| angle | The rotation angle, in radians. |
如需将角度转换为弧度,请使用 *degrees**Math.PI/180 公式进行计算。
实例:如需旋转 5 度,可Specifies下面的公式:5*Math.PI/180。 |
Canvas object