Latest web development tutorials

HTML canvas lineTo () method

HTML canvas Reference Manual HTML canvas Reference Manual

Examples

Start a path, to the position 0,0. 300, 150 reaches a position to create a line:

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"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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


Definition and Usage

lineTo () method to add a new point, and then create a line from that point to the canvas in the last specified point (this method does not create a line).

Tip: Use the stroke () method to draw the exact path on the canvas.

JavaScript syntax: context.lineTo (x, y);

Parameter Value

参数 描述
x 路径的目标位置的 x 坐标。
y 路径的目标位置的 y 坐标。


Examples

More examples

Examples

Draw a path shape is the letter L:

YourbrowserdoesnotsupporttheHTMLcanvastag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.moveTo(20,20);
ctx.lineTo(20,100);
ctx.lineTo(70,100);
ctx.stroke();

try it"


HTML canvas Reference Manual HTML canvas Reference Manual