DOMMatrix
interface represents 4×4 matrices, suitable for 2D and 3D operations including rotation and translation. It is a mutable version of the
DOMMatrixReadOnly
接口。
This interface should be available inside web workers , though some implementations don't allow it yet.
DOMMatrix()
DOMMatrix
对象。
此接口继承特性从
DOMMatrixReadOnly
, though some of these properties are altered to be mutable.
is2D
只读
true
if the matrix was initialized as a 2D matrix. If
false
, the matrix is 3D.
isIdentity
只读
true
if the matrix is the
identity matrix
. The identity matrix is one in which every value is
0
except
those on the main diagonal from top-left to bottom-right corner (in other words, where the offsets in each direction are equal).
m11
,
m12
,
m13
,
m14
,
m21
,
m22
,
m23
,
m24
,
m31
,
m32
,
m33
,
m34
,
m41
,
m42
,
m43
,
m44
m11
透过
m14
are the first column,
m21
透过
m24
are the second column, and so forth.
a
,
b
,
c
,
d
,
e
,
f
Double-precision floating-point values representing the components of a 4×4 matrix which are required in order to perform 2D rotations and translations. These are aliases for specific components of a 4×4 matrix, as shown below.
2D
|
3D equivalent
|
|---|---|
a
|
m11
|
b
|
m12
|
c
|
m21
|
d
|
m22
|
e
|
m41
|
f
|
m42
|
This interface includes the following methods, as well as the methods it inherits from
DOMMatrixReadOnly
.
DOMMatrix.invertSelf()
NaN
,和
is2D
返回
false
.
DOMMatrix.multiplySelf()
DOMMatrix
. This is equivalent to the dot product
A⋅B
, where matrix
A
is the source matrix and
B
is the matrix given as an input to the method. Returns itself.
DOMMatrix.preMultiplySelf()
DOMMatrix
. This is equivalent to the dot product
B⋅A
, where matrix
A
is the source matrix and
B
is the matrix given as an input to the method. Returns itself.
DOMMatrix.translateSelf()
[0, 0, 0]
. Returns itself.
DOMMatrix.scaleNonUniformSelf()
1
, but the scaling factor for X must be specified. The default origin is
(0, 0, 0)
. Returns itself.
DOMMatrix.scaleSelf()
1
for all three axes, and the origin is
(0, 0, 0)
. Returns itself.
DOMMatrix.scale3dSelf()
Modifies the matrix by applying the specified scaling factor to all three axes, centered on the given origin. Returns itself.
DOMMatrix.rotateSelf()
Modifies the matrix by rotating itself around each axis by the specified number of degrees. Returns itself.
DOMMatrix.rotateAxisAngleSelf()
Modifies the matrix by rotating it by the specified angle around the given vector. Returns itself.
DOMMatrix.rotateFromVectorSelf()
(1, 0)
. Returns itself.
DOMMatrix.setMatrixValue()
Replaces the contents of the matrix with the matrix described by the specified transform or transforms. Returns itself.
DOMMatrix.skewXSelf()
Modifies the matrix by applying the specified skew transformation along the X-axis. Returns itself.
DOMMatrix.skewYSelf()
Modifies the matrix by applying the specified skew transformation along the Y-axis. Returns itself.
This interface inherits methods from
DOMMatrixReadOnly
.
fromFloat32Array()
DOMMatrix
object given an array of single-precision (32-bit) floating-point values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, a
TypeError
exception is thrown.
fromFloat64Array()
DOMMatrix
object given an array of double-precision (64-bit) floating-point values. If the array has six values, the result is a 2D matrix; if the array has 16 values, the result is a 3D matrix. Otherwise, a
TypeError
exception is thrown.
fromMatrix()
DOMMatrix
object given an existing matrix or a
DOMMatrixInit
dictionary which provides the values for its properties.
The matrix defined by the
DOMMatrix
interface is comprised of four rows of four columns each. While it's beyond the scope of this article to explain the mathematics involved, this 4×4 size is enough to describe any transformation you might apply to either 2D or 3D geometries.
DOMMatrix
interface is designed with the intent that it will be used for all matrices within markup, supplanting the
SVGMatrix
and
CSSMatrix
接口。
| 规范 | 状态 | 注释 |
|---|---|---|
|
Geometry Interfaces Module Level 1
The definition of 'DOMMatrix' in that specification. |
候选推荐 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
DOMMatrix
|
Chrome
61
|
Edge
79
|
Firefox 33 | IE No |
Opera
48
|
Safari 11 | WebView Android 61 |
Chrome Android
61
|
Firefox Android 33 |
Opera Android
48
|
Safari iOS 11 | Samsung Internet Android 8.0 |
DOMMatrix()
构造函数
|
Chrome 45 | Edge 79 | Firefox 33 | IE No | Opera 32 | Safari 11 | WebView Android 61 | Chrome Android 45 | Firefox Android 33 | Opera Android 32 | Safari iOS 11 | Samsung Internet Android 8.0 |
scale3dSelf()
|
Chrome 45 | Edge 79 |
Firefox
33
|
IE No | Opera 32 | Safari 11 | WebView Android 61 | Chrome Android 45 |
Firefox Android
33
|
Opera Android 32 | Safari iOS 11 | Samsung Internet Android 8.0 |
scaleSelf()
|
Chrome 45 | Edge 79 |
Firefox
33
|
IE No | Opera 32 | Safari 11 | WebView Android 61 | Chrome Android 45 |
Firefox Android
部分支持
33
|
Opera Android 32 | Safari iOS 11 | Samsung Internet Android 8.0 |
| Available in workers | Chrome 57 | Edge 79 | Firefox 69 | IE No | Opera 44 | Safari 11 | WebView Android 61 | Chrome Android 57 | Firefox Android No | Opera Android 43 | Safari iOS 11 | Samsung Internet Android 8.0 |
完整支持
部分支持
不支持
见实现注意事项。
用户必须明确启用此特征。
DOMMatrixReadOnly
SVGMatrix
, the SVG matrix intended to be superseded by
DOMMatrix
DOMMatrix