HTML canvas moveTo() 方法

定义和用法

moveTo() 方法将路径移动到画布中的指定点,而不创建线。

提示:请使用 stroke() 方法在画布上绘制确切的路径。

实例

开始一条路径,移动到位置 0,0。创建到达位置 300,150 的一条线:

您的浏览器不支持HTML5 canvas标签。

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

Syntax

context.moveTo(x,y);

Parameter Value

Parameter Description
x The x-coordinate of the target location of the path
y The y-coordinate of the target location of the path

Browser Support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

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