HTML canvas moveTo()Methods

HTML canvas 参考手册HTML canvas Reference Manual

Example

Start a path, move to position 0,0. Create a line to position 300,150:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(300,150);
ctx.stroke();

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


Definition and Usage

The moveTo() method moves the path to the specified point on the canvas, without creating a line.

Tip:Please usestroke()method to draw an exact path on the canvas.

JavaScript Syntax: context.moveTo(x,y);

Parameter Values

Parameter Description
x The x coordinate of the target position of the path.
y The y coordinate of the target position of the path.


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