HTML canvas moveTo()Method

Canvas 对象参考手册Canvas Object

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 a specified point on the canvas, without creating a line.

Tip:Please use thestroke()method to draw the 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.


Canvas 对象参考手册Canvas Object

Other Extensions