The getLineDash()
method of the Canvas 2D API's CanvasRenderingContext2D
interface gets the current line dash pattern.
The getLineDash()
method of the Canvas 2D API's CanvasRenderingContext2D
interface gets the current line dash pattern.
js
getLineDash()
None.
An Array
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]
.
This example demonstrates the getLineDash()
method.
html
<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.
js
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();
Specification |
---|
HTML Standard # dom-context-2d-getlinedash-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
getLineDash |
23 | 12 | 27 | 11 | 15 | 7 | 4.4 | 25 | 27 | 14 | 7 | 1.5 |
CanvasRenderingContext2D
CanvasRenderingContext2D.setLineDash()
CanvasRenderingContext2D.lineDashOffset
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getLineDash