CanvasRenderingContext2D.getLineDash()

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

The getLineDash() method of the Canvas 2D API's CanvasRenderingContext2D interface gets the current line dash pattern.

Syntax

ctx.getLineDash();

Return value

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].

Examples

Getting the current line dash setting

This example demonstrates the getLineDash() method.

HTML

<canvas id="canvas"></canvas>

JavaScript

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();

Result

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'CanvasRenderingContext2D.getLineDash' in that specification.
Living Standard  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support 12Firefox Full support 27IE Full support 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 27Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

Gecko-specific notes

  • Starting with Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), the non-standard and deprecated property mozDash has been implemented to set and get a dash list. This property will be deprecated and removed in the future, see bug 931389. Use getLineDash() instead.

WebKit-specific notes

  • In WebKit-based browsers (e.g., Safari), the non-standard and deprecated property webkitLineDash is implemented besides this method. Use getLineDash() instead.

See also

ドキュメントのタグと貢献者

このページの貢献者: mfluehr, fscholz, thatmichael85, nmve, erikadoyle
最終更新者: mfluehr,