Created
January 24, 2013 15:37
-
-
Save desandro/4623257 to your computer and use it in GitHub Desktop.
getStyleProperty
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
/*! | |
* getStyleProperty by kangax | |
* http://perfectionkills.com/feature-testing-css-properties/ | |
*/ | |
/*jshint browser: true, strict: true, undef: true */ | |
( function( window ) { | |
'use strict'; | |
var prefixes = 'Webkit Moz ms Ms O'.split(' '); | |
var docElemStyle = document.documentElement.style; | |
function getStyleProperty( propName ) { | |
// test standard property first | |
if ( typeof docElemStyle[ propName ] === 'string' ) { | |
return propName; | |
} | |
// capitalize | |
propName = propName.charAt(0).toUpperCase() + propName.slice(1); | |
// test vendor specific properties | |
var prefixed; | |
for ( var i=0, len = prefixes.length; i < len; i++ ) { | |
prefixed = prefixes[i] + propName; | |
if ( typeof docElemStyle[ prefixed ] === 'string' ) { | |
return prefixed; | |
} | |
} | |
} | |
// publicize | |
window.getStyleProperty = getStyleProperty; | |
})( window ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment