CanvasRenderingContext2D
.moveTo()
method of the Canvas 2D API begins a new sub-path at the point specified by the given
(x, y)
坐标。
void ctx.moveTo(x, y);
x
The x-axis (horizontal) coordinate of the point.
y
The y-axis (vertical) coordinate of the point.
此范例使用
moveTo()
to create two sub-paths within a single path. Both sub-paths are then rendered with a single
stroke()
调用。
<canvas id="canvas"></canvas>
The first line begins at (50, 50) and ends at (200, 50). The second line begins at (50, 90) and ends at (280, 120).
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(50, 50); // Begin first sub-path
ctx.lineTo(200, 50);
ctx.moveTo(50, 90); // Begin second sub-path
ctx.lineTo(280, 120);
ctx.stroke();
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'CanvasRenderingContext2D.moveTo' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
moveTo
|
Chrome 1 | Edge 12 | Firefox 1.5 | IE 9 | Opera 11.6 | Safari 2 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 12 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持
CanvasRenderingContext2D
CanvasRenderingContext2D.lineTo()
CanvasRenderingContext2D.stroke()
CanvasRenderingContext2D
addHitRegion()
arc()
arcTo()
beginPath()
bezierCurveTo()
clearHitRegions()
clearRect()
clip()
closePath()
createImageData()
createLinearGradient()
createPattern()
createRadialGradient()
drawFocusIfNeeded()
drawImage()
drawWidgetAsOnScreen()
drawWindow()
ellipse()
fill()
fillRect()
fillText()
getImageData()
getLineDash()
getTransform()
isPointInPath()
isPointInStroke()
lineTo()
measureText()
moveTo()
putImageData()
quadraticCurveTo()
rect()
removeHitRegion()
resetTransform()
restore()
rotate()
save()
scale()
scrollPathIntoView()
setLineDash()
setTransform()
stroke()
strokeRect()
strokeText()
transform()
translate()