W3cubDocs

/DOM

CanvasRenderingContext2D.currentTransform

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

Using the currentTransform method

This is just a simple code snippet that uses the currentTransform property to set a transformation matrix.

HTML

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

JavaScript

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

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

Edit the code below and see your changes update live in the canvas (make sure to use a browser that supports this feature — see the compatibility table):

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes
Disabled
Yes
Disabled
Disabled This feature is behind the Experimental Web Platform Features preference. To change preferences in Chrome, visit chrome://flags.
Yes No
No
See bug 928150. Firefox also supports the experimental and prefixed properties mozCurrentTransform and mozCurrentTransformInverse which set or get the current (inverse) transformation matrix.
No No No
No
See webkitbug(174278).
Returns a DOMMatrix No
No
See https://crbug.com/637940.
? ? No No No
No
See webkitbug(174278).
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support No No Yes No No No No
Returns a DOMMatrix No
No
See https://crbug.com/637940.
No
No
See https://crbug.com/637940.
Yes ? ? ? No

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/currentTransform