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

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The CanvasRenderingContext2D.currentTransform property of the Canvas 2D API returns or sets a DOMMatrix (current specification) or SVGMatrix (old specification) object for the current transformation matrix.

Syntax

ctx.currentTransform [= value];
value
A DOMMatrix or SVGMatrix object to use as the current transformation matrix.

Examples

Manually changing the matrix

This example uses the currentTransform property to set a transformation matrix. A rectangle is then drawn using that transformation.

HTML

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

JavaScript

const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

let matrix = ctx.currentTransform;
matrix.a = 1;
matrix.b = 1;
matrix.c = 0;
matrix.d = 1;
matrix.e = 0;
matrix.f = 0;
ctx.currentTransform = matrix;
ctx.fillRect(0, 0, 100, 100);

Result

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
currentTransform
Experimental
Chrome Full support Yes
Disabled
Full support Yes
Disabled
Disabled This feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Edge Full support YesFirefox No support No
Notes
No support No
Notes
Notes See bug 928150. Firefox also supports the experimental and prefixed properties mozCurrentTransform and mozCurrentTransformInverse which set or get the current (inverse) transformation matrix.
IE No support NoOpera No support NoSafari No support No
Notes
No support No
Notes
Notes See webkitbug(174278).
WebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
Returns a DOMMatrix
Experimental
Chrome No support No
Notes
No support No
Notes
Notes See bug 637940.
Edge ? Firefox No support NoIE No support NoOpera No support NoSafari No support No
Notes
No support No
Notes
Notes See bug 174278.
WebView Android No support No
Notes
No support No
Notes
Notes See bug 637940.
Chrome Android No support No
Notes
No support No
Notes
Notes See bug 637940.
Firefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

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

最終更新者: mdnwebdocs-bot,