Created
December 22, 2010 11:55
-
-
Save benbarnett/751425 to your computer and use it in GitHub Desktop.
Calculate translation from transform matrix
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
function translation(elem) { | |
var cssPrefixes = ["", "-webkit-", "-moz-", "-o-"], | |
cStyle = window.getComputedStyle(elem, null), | |
translation = { | |
x: 0, | |
y: 0 | |
}; | |
for (var i = cssPrefixes.length - 1; i >= 0; i--){ | |
var transform = cStyle.getPropertyValue(cssPrefixes[i] + "transform"); | |
if (transform && (/matrix/i).test(transform)) { | |
var explodedMatrix = transform.replace(/^matrix\(/i, '').split(/, |\)$/g); | |
translation = { | |
x: explodedMatrix[4], | |
y: explodedMatrix[5] | |
}; | |
break; | |
} | |
} | |
return translation; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment