Skip to content

Instantly share code, notes, and snippets.

@blob42
Last active February 10, 2016 14:16
Show Gist options
  • Select an option

  • Save blob42/7bd8dec2106b6c7b9997 to your computer and use it in GitHub Desktop.

Select an option

Save blob42/7bd8dec2106b6c7b9997 to your computer and use it in GitHub Desktop.
function matFromEl(element) {
var transform = getComputedStyle(element).transform;
var t = /^matrix\((\S*), (\S*), (\S*), (\S*), (\S*), (\S*)\)$/g.exec(transform),
a = parseFloat(!t ? 1 : t[1]),
b = parseFloat(!t ? 0 : t[2]),
c = parseFloat(!t ? 0 : t[3]),
d = parseFloat(!t ? 1 : t[4]),
e = parseFloat(!t ? 0 : t[5]),
f = parseFloat(!t ? 0 : t[6]);
function getObject() {
return {a:a, b:b, c:c, d:d, e:e, f:f};
}
function getArray() {
return {a, b, c, d, e, f};
}
return {
getObject: getObject,
getArray: getArray
}
}
function arrayMatToString(m) {
var s = 'matrix(',
c;
for (c=0, c<m.length, c++) {
s += m[c] + ','
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment