English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
lineTo() is a Canvas 2The D API uses a method to connect the end of a subpath to x, y coordinates with a straight line (this does not actually draw).
Start a path and move to position 0,0. Create a path that reaches 300,15A line: 0 of
<!DOCTYPE html> <html> <head> <meta charset="utf-8> <title>HTML canvas lineTo() method usage-Basic Tutorial(oldtoolbag.com)</title>/<title> </<head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3> Your browser does not support HTML5 canvas tag. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.beginPath(); ctx.moveTo(0,0); ctx.lineTo(300,150); ctx.stroke(); </script> </body> </html>Test and see ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9Firefox, Opera, Chrome, and Safari support lineTo() Method.
Note:Internet Explorer 8 And earlier versions do not support the <canvas> element.
The lineTo() method adds a new point and then creates a line from that point to the last specified point on the canvas (this method does not create a line).
Tip:Please use stroke() Method to draw an exact path on the canvas.
JavaScript Syntax: | context.lineTo(x,y); |
---|
Parameter | Description |
---|---|
x | The x-coordinate of the target position of the path. |
y | The y-coordinate of the target position of the path. |
Draw a path with the shape of the letter L:
<!DOCTYPE html> <html> <head> <meta charset="utf-8> <title>HTML canvas lineTo() method usage-Basic Tutorial(oldtoolbag.com)</title>/<title> </<head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3> Your browser does not support HTML5 canvas tag. </canvas> <script> 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(); </script> </body> </html>Test and see ‹/›