Skip to content

Instantly share code, notes, and snippets.

@neilrackett
Created February 6, 2018 16:19
Show Gist options
  • Save neilrackett/2dc772d2fe3b2f1e58fe80558fa974eb to your computer and use it in GitHub Desktop.
Save neilrackett/2dc772d2fe3b2f1e58fe80558fa974eb to your computer and use it in GitHub Desktop.
Update the X and Y translation values of a CSS transform (e.g. to move an SVG group or object)
let myTransform;
myTransform = "translate(100,200) scale(1)";
myTransform = myTransform.replace(/(.*?translate\()(.*?)(,)(.*?)(\).*)/, (all:string, prefix:string, x:string, comma:string, y:string, suffix:string) =>
{
return `${prefix}${~~x+100}${comma}${~~y+100}${suffix}`;
});
console.log(myTransform); // Output: "translate(200,300) scale(1)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment