Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active September 6, 2016 11:24
Show Gist options
  • Save vincentorback/918fb42f3577f632b1df to your computer and use it in GitHub Desktop.
Save vincentorback/918fb42f3577f632b1df to your computer and use it in GitHub Desktop.
Apply style prefixed with all prefixes
const PREFIXES = ['', 'Moz', 'webkit', 'Webkit', 'O', 'ms'];
function applyStyle(prop, value, element) {
const first = prop[0];
const trail = prop.slice(1);
PREFIXES.forEach(prefix => {
let name = prefix ? (prefix + first.toUpperCase()) : first.toLowerCase();
name += trail;
el.style[name] = value;
});
}
/* applyStyle('transform', 'translate(50%, 50%)', element); */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment