Last active
September 6, 2016 11:24
-
-
Save vincentorback/918fb42f3577f632b1df to your computer and use it in GitHub Desktop.
Apply style prefixed with all prefixes
This file contains 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
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