HTML canvas rotate()Method

Canvas 对象参考手册Canvas Object

Examples

Rotate the rectangle by 20 degrees:

YourbrowserdoesnotsupporttheHTML5canvastag.

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 Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the rotate() method.

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.


Definition and Usage

The rotate() method rotates the current drawing.

Note:The rotation only affects the drawing that is done after the rotation.

JavaScript Syntax: context.rotate(angle);

Parameter Values

Parameter Description
angle The rotation angle, in radians.

If you need to convert degrees to radians, usedegreesthe *Math.PI/180 formula to calculate.
Example: To rotate 5 degrees, specify the following formula: 5*Math.PI/180.


Canvas 对象参考手册Canvas Object

Other Extensions