function getTransformValues(element) {
const style = window.getComputedStyle(element);
const matrix =
style.transform || style.webkitTransform || style.mozTransform;
const matrixType = matrix.includes("3d") ? "3d" : "2d";
const matrixValues = matrix.match(/matrix.*\((.+)\)/)[1].split(", ");
// 2d matrices have 6 values
if (matrixType === "2d") {
return {
x: Number(matrixValues[4]),
y: Number(matrixValues[5])
};
}
// 3d matrices have 16 values
if (matrixType === "3d") {
return {
x: Number(matrixValues[12]),
y: Number(matrixValues[13]),
z: Number(matrixValues[14]),
};
}
}
}
getTransformValues(твойЭлемент); // { x: 0, y: 0, z: 0 }