Created
February 6, 2018 16:19
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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