Skip to content

Instantly share code, notes, and snippets.

@DoubleCouponDay
Last active September 26, 2019 01:43
Show Gist options
  • Select an option

  • Save DoubleCouponDay/cbf72881dc725347b40d8a048e46fac9 to your computer and use it in GitHub Desktop.

Select an option

Save DoubleCouponDay/cbf72881dc725347b40d8a048e46fac9 to your computer and use it in GitHub Desktop.
const nooccurrence = -1
export function translateelement(element: HTMLElement | SVGElement, translationkey: string, translationvalue: string) {
let newtransform = `${translationkey}(${translationvalue})`
if(element.style.transform.indexOf(translationkey) !== nooccurrence) {
let anyvalueregex = new RegExp(`${translationkey}\\(.+\\)`) //any translationvalue one or more times
let replacement = element.style.transform.replace(anyvalueregex, newtransform)
element.style.transform = replacement
}
else {
element.style.transform += newtransform
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment