Reputation: 528
I have a variable called transformstyle
which returns me the transformation style of another element.
For example: console.log(transformstyle);
would return translate(155%, -259%) scale(0.6)
I want to make modifications to the transformation, for example I want to do translate(155% + 30%, -259% - 115%);
How can I access the interior of the transformation to make these changes?
Upvotes: 0
Views: 88
Reputation: 724
you can do some hack like this.
var s = "translate(155%, -259%)"; /*transformstyle*/
s = s.replace(/[()]/g,",");
s = s.replace(/[%]/g,"");
var x = Number(s.split(",")[1]);
var y = Number(s.split(",")[2]);
var newX = 30;
var newY = -115;
var newTransformstyle = 'translate('+(x+newX)+'%,' +(y+newY)+'%)';
console.log(newTransformstyle);
Upvotes: 2