aderaaij
9/4/2017 - 12:31 PM

Get the computed Translate X and Y values of a given DOM element. Based on https://stackoverflow.com/questions/21912684/how-to-get-value-of-

Get the computed Translate X and Y values of a given DOM element. Based on https://stackoverflow.com/questions/21912684/how-to-get-value-of-translatex-and-translatey

function getComputedTranslateXY(obj)
{
	const transArr = [];
    if(!window.getComputedStyle) return;
    const style = getComputedStyle(obj),
        transform = style.transform || style.webkitTransform || style.mozTransform;
    let mat = transform.match(/^matrix3d\((.+)\)$/);    
    if(mat) return parseFloat(mat[1].split(', ')[13]);
    mat = transform.match(/^matrix\((.+)\)$/);
    mat ? transArr.push(parseFloat(mat[1].split(', ')[4])) : 0;
    mat ? transArr.push(parseFloat(mat[1].split(', ')[5])) : 0;
    return transArr;
}