Created
August 24, 2018 05:57
-
-
Save phoenisx/b289de3900fe54aadd36731d16542c17 to your computer and use it in GitHub Desktop.
Helps to get translate values from a matrix string, from `window.getComputedStyle`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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