Skip to content

Instantly share code, notes, and snippets.

@phoenisx
Created August 24, 2018 05:57
Show Gist options
  • Save phoenisx/b289de3900fe54aadd36731d16542c17 to your computer and use it in GitHub Desktop.
Save phoenisx/b289de3900fe54aadd36731d16542c17 to your computer and use it in GitHub Desktop.
Helps to get translate values from a matrix string, from `window.getComputedStyle`
/**
* Returns null if the Transform is not pre-calculated as a matrix string...
* else returns the translateY in Pixels...
*
* @param matrix: `window.getComputedStyle({ELEMENT}).getPropertyValue('transform')`
*
* Example: matrix = 'matrix(1, 0, 0, 1, 101.2, 186)' // [4]: translateX, [5]: translateY
*/
getTranslateYFromMatrix = (matrix) => {
const match = matrix.match(/\((.*)\)/)[1];
if (match) {
return window.parseInt(match.split(',')[5], 10);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment