getLineDash()
method of the Canvas 2D API's
CanvasRenderingContext2D
interface gets the current line dash pattern.
ctx.getLineDash();
数组
of numbers that specify distances to alternately draw a line and a gap (in coordinate space units). If the number, when setting the elements, is odd, the elements of the array get copied and concatenated. For example, setting the line dash to
[5, 15, 25]
will result in getting back
[5, 15, 25, 5, 15, 25]
.
此范例演示
getLineDash()
方法。
<canvas id="canvas"></canvas>
As set by
setLineDash()
, strokes consist of lines that are 10 units wide, with spaces of 20 units in between each line.
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.setLineDash([10, 20]);
console.log(ctx.getLineDash()); // [10, 20]
// Draw a dashed line
ctx.beginPath();
ctx.moveTo(0, 50);
ctx.lineTo(300, 50);
ctx.stroke();
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'CanvasRenderingContext2D.getLineDash' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getLineDash
|
Chrome Yes | Edge 12 | Firefox 27 | IE 11 | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 27 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
CanvasRenderingContext2D
CanvasRenderingContext2D.setLineDash()
CanvasRenderingContext2D.lineDashOffset
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()