HTML canvas rotate()Method

HTML canvas 参考手册HTML canvas Reference Manual

Example

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:Rotation only affects drawings made after the rotation is completed.

JavaScript Syntax: context.rotate(angle);

Parameter Values

Parameter Description
angle The rotation angle, in radians.

To convert degrees to radians, use thedegrees*Math.PI/180 formula for calculation.
Example: To rotate 5 degrees, specify the following formula: 5*Math.PI/180.


HTML canvas 参考手册HTML canvas Reference Manual Other Extensions