The DOMMatrix
constructor creates a new DOMMatrix
object which represents 4x4 matrices, suitable for 2D and 3D operations.
DOMMatrix()
Syntax
new DOMMatrix() new DOMMatrix(init)
Parameters
- init Optional
-
An array of numbers specifying the matrix you want to create, or a CSS transform string.
In case an array of numbers is passed, the behavior depends on the length of the array:
- for a 6-element array of components in the form
[a, b, c, d, e, f]
, a 2D matrix is created, initialized with the provided components. - for a 16-element array of components (in the column-major order) in the form
[m11, m12, m13, …, m42, m43, m44]
, a 3D matrix is created, initialized with the provided components.
- for a 6-element array of components in the form
Examples
This example creates a DOMMatrix to use as an argument for calling Point.matrixTransform()
.
var point = new DOMPoint(5, 4); var scaleX = 2; var scaleY = 3; var translateX = 12; var translateY = 8; var angle = Math.PI / 2; var matrix = new DOMMatrix([ Math.sin(angle) * scaleX, Math.cos(angle) * scaleX, -Math.sin(angle) * scaleY, Math.cos(angle) * scaleY, translateX, translateY ]); var transformedPoint = point.matrixTransform(matrix);
Specifications
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
DOMMatrix |
61
|
79
|
33
|
No
|
48
|
11
|
61
|
61
|
33
|
45
|
11
|
8.0
|
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix/DOMMatrix