moveTo method
Creates a new subpath by using the specified point.
![]() ![]() |
Syntax
var retval = CanvasRenderingContext2D.moveTo(x, y);Parameters
- x [in]
-
Type: Floating-point
The x-coordinate, in pixels.
- y [in]
-
Type: Floating-point
The y-coordinate, in pixels.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Standards information
- HTML Canvas 2D Context, Section 9
Examples
The following code example uses the moveTo and lineTo methods to incrementally draw horizontal lines across the canvas.
<!DOCTYPE html> <html>
<head>
<script type="text/javascript">
function draw()
{
var canvas = document.getElementById("MyCanvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
for(i=10;i<500;i+=20)
{
ctx.moveTo(0,i);
ctx.lineTo(canvas.width,i);
ctx.stroke();
}
}
}
</script>
</head>
<body onload="draw()">
<canvas id="MyCanvas" width="600" height="600"> </canvas>
</body>
</html>
See also
Send comments about this topic to Microsoft
Build date: 11/28/2012

