Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
Last active December 17, 2015 15:18
Show Gist options
  • Save quidmonkey/5630335 to your computer and use it in GitHub Desktop.
Save quidmonkey/5630335 to your computer and use it in GitHub Desktop.
Get Vendor Prefix for a CSS attribute
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