Skip to content

Instantly share code, notes, and snippets.

@davemackintosh
Last active April 29, 2016 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davemackintosh/b08ee2261462b44a7d7cf33c832ad2a9 to your computer and use it in GitHub Desktop.
Save davemackintosh/b08ee2261462b44a7d7cf33c832ad2a9 to your computer and use it in GitHub Desktop.
// All the transform types.
const types = [
"translate",
"translateX",
"translateY",
"scale",
"scaleX",
"scaleY",
"rotate",
"skew",
"skewX",
"skewY",
"matrix3d",
"translate3d",
"translateZ",
"scale3d",
"scaleZ",
"rotate3d",
"rotateX",
"rotateY",
"rotateZ",
"perspective"
]
const props = {}
types.forEach(type => {
Object.defineProperty(props, type, {
set: function(value) {
if (!~this.transform.indexOf(type)) {
this.transform.splice(0, 0, `${type}(${value})`)
}
else {
this.transform.replace(new RegExp(`${type}\((.*)\)`, "gi"), value)
}
}
})
})
// Deal with it 😠
CSSStyleDeclaration.prototype.transforms = props
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment