JavaScript Function To Extract Information From CSS Transform Matrix Property

function extractTransformData(data) {
  let matrixRegex = /matrix\(\s*(-?\d*\.?\d*),\s*(-?\d*\.?\d*),\s*(-?\d*\.?\d*),\s*(-?\d*\.?\d*),\s*(-?\d*\.?\d*),\s*(-?\d*\.?\d*)\)/;
  return data.match(matrixRegex);
}

Passing in the CSS transform property that looks like this:

matrix(0.577116, 0, 0, 0.577116, -873, -607)

Will return an array like this:

transform: Array(7)
0: "matrix(0.577116, 0, 0, 0.577116, -873, -607)"
1: "0.577116"
2: "0"
3: "0"
4: "0.577116"
5: "-873"
6: "-607"

 

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.