API Docs for:
Show:

CSSMatrix2d Class

This represents the matrix used by 2d CSS transforms. It helps perform all of the necessary matrix calculations. This is sort of an implementation of the CSSMatrix object defined in this spec: http://www.w3.org/TR/css3-2d-transforms/#cssmatrix-interface The matrix defined in the spec is a 3x2 matrix. I'm not exactly an expert at matrix math, but most of the operations required by the spec only work with square matrices. The spec doesn't explain how a 3x2 matrix is supposed to do these things. In order to make the math work correctly, this object internally treats it as the 4x4 matrix defined in the 3d CSS transforms spec here: http://www.w3.org/TR/css3-3d-transforms/#cssmatrix-interface and it converts the 3x2 matrix into a 4x4 matrix by following the examples provided in this spec: http://www.w3.org/TR/2012/WD-css3-transforms-20120403/ Other implementations of these specs, like the WebKitCSSMatrix object and others that have copied it, attempt to combine both the 2d and 3d versions of CSSMatrix into the same object. This implementation only borrows ideas from the 3d version to make the math make sense, but only the 2d functionality is implemented. Since only the 6 2d matrix items out of the total 16 3d matrix items are mutable, and the remaining 3d matrix items are known to be either 0 or 1, most of the complicated 4x4 matrix math is factored down and reduced, becoming much more efficient.

Constructor

Methods

inverse

() CSSMatrix2d

Returns a new matrix, the inverse of this one. This matrix is not modified. This method will throw if the matrix can not be inverted.

Returns:

CSSMatrix2d: inverse

multiply

(
  • other
)
CSSMatrix2d

Returns a new matrix, the product of this one multiplied by another one. Neither this matrix nor the other one is modified.

Parameters:

Returns:

CSSMatrix2d: product

rotate

(
  • angle
)
CSSMatrix2d

Returns a new matrix, rotated the given angle clockwise. This matrix is not modified.

Parameters:

  • angle Number

    The angle specified in degrees.

Returns:

CSSMatrix2d: rotated

rotateRad

(
  • angle
)
CSSMatrix2d

Returns a new matrix, rotated the given angle clockwise. This matrix is not modified.

Parameters:

  • angle Number

    The angle specified in radians.

Returns:

CSSMatrix2d: rotated

scale

(
  • x
  • y
)
CSSMatrix2d

Returns a new matrix, scaled horizontally and vertically. This matrix is not modified.

Parameters:

  • x Number

    The horizontal scale factor.

  • y Number

    The vertical scale factor. Optional. If undefined, x will be used for both the horizontal and vertical scale factor.

Returns:

CSSMatrix2d: scaled.

setMatrixValue

(
  • matrixValue
)
chainable

Sets the matrix based on a matrix string provided by the DOM. The string is expected to be like 'matrix(a, b, c, d, e, f)'. This format isn't specifically checked for, so other similar strings might be accepted. If 6 values can not be read from from the string, this method will do nothing. Invalid values could result in NaN being assigned to matrix items.

Parameters:

skewX

(
  • angle
)
CSSMatrix2d

Returns a new matrix, skewed horizontally. This matrix is not modified.

Parameters:

  • angle Number

    The horizontal skew angle specified in degrees.

Returns:

CSSMatrix2d: skewed.

skewXRad

(
  • angle
)
CSSMatrix2d

Returns a new matrix, skewed horizontally. This matrix is not modified.

Parameters:

  • angle Number

    The horizontal skew angle specified in radians.

Returns:

CSSMatrix2d: skewed.

skewY

(
  • angle
)
CSSMatrix2d

Returns a new matrix, skewed vertically. This matrix is not modified.

Parameters:

  • angle Number

    The vertical skew angle specified in degrees.

Returns:

CSSMatrix2d: skewed.

skewYRad

(
  • angle
)
CSSMatrix2d

Returns a new matrix, skewed vertically. This matrix is not modified.

Parameters:

  • angle Number

    The vertical skew angle specified in radians.

Returns:

CSSMatrix2d: skewed.

toString

() String

Returns a string 'matrix(a, b, c, d, e, f)' which can be used by the DOM for 2d CSS transforms.

Returns:

translate

(
  • x
  • y
)
CSSMatrix2d

Returns a new matrix, translated horizontally and vertically. This matrix is not modified.

Parameters:

  • x Number

    The horizontal translation amount.

  • y Number

    The vertical translation amount.

Returns:

CSSMatrix2d: translated.

Properties

a

Number

The 1,1 position in the matrix.

Default: 1

b

Number

The 2,1 position in the matrix.

Default: 0

c

Number

The 1,2 position in the matrix.

Default: 0

d

Number

The 2,2 position in the matrix.

Default: 1

e

Number

The 1,4 position in the matrix.

Default: 0

f

Number

The 2,4 position in the matrix.

Default: 0