Skip to content

Instantly share code, notes, and snippets.

@webcyou
Created September 17, 2014 17:05
Show Gist options
  • Save webcyou/56fa6a63c845a6f516cc to your computer and use it in GitHub Desktop.
Save webcyou/56fa6a63c845a6f516cc to your computer and use it in GitHub Desktop.
get transform val
var div = document.getElementById("result"),
elm = document.getElementById("elm");
var computedStyle,mat,a,b,c,d,e,f,
reMat = /matrix\(\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*\,\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*\)/;
computedStyle = window.getComputedStyle(elm, null);
mat = computedStyle['-webkit-transform'].match(reMat).slice(1);
a = parseFloat(mat[0], 10);
b = parseFloat(mat[1], 10);
c = parseFloat(mat[2], 10);
d = parseFloat(mat[3], 10);
e = parseFloat(mat[4], 10);
f = parseFloat(mat[5], 10);
div.innerHTML = "mat:" + mat + "<br>" + "a:" + a + "<br>" + "b:" + b + "<br>" + "c:" + c + "<br>" + "d:" + d + "<br>" + "e:" + e + "<br>" + "f:" + f + "<br>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment