-
-
Save quidmonkey/5630335 to your computer and use it in GitHub Desktop.
Get Vendor Prefix for a CSS attribute
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
function css (css) { | |
var browser = window.navigator.userAgent.toLowerCase().match(/chrome|firefox|opera|msie|safari/)[0]; | |
var attribute = browser === 'chrome' || browser === 'opera' || browser === 'safari' ? '-webkit-' + css : | |
browser === 'firefox' ? '-moz-' + css : | |
browser === 'msie' ? '-ms-' + css : | |
css; | |
var styles = document.documentElement.style; | |
if (typeof styles[attribute] !== 'undefined') { | |
return attribute; | |
} else if (typeof styles[css] !== 'undefined') { | |
return css; | |
} else { | |
console.error('*** Unknown style attribute ***'); | |
return ''; | |
} | |
} | |
var div = document.getElementById('myDiv'); | |
div.style[css('transform')] = 'rotate(180deg)'; // rotate 180 degrees in any browser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment