-
-
Save Ser-Gen/5501521 to your computer and use it in GitHub Desktop.
Проверка поддержки CSS-свойств
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
// позволяет проверить, поддерживается ли CSS-свойство. | |
// если да, возвращается свойство с нужным браузеру префиксом, нет — false | |
// например, | |
// var e = document.getElementById( 'element' ), | |
// s = prefix( 'transform' ); | |
// if (s) { | |
// e.style[s] = 'rotate( 45deg )'; | |
// } | |
// | |
function prefix (property) { | |
var propertyUC = property.replace(/-(\w)/g,function(s,g){return g.toUpperCase()}); | |
var vendors = ['', 'Webkit', 'Moz', 'O', 'ms']; | |
for(var i = 0, len = vendors.length; i < len; i++) { | |
var vendor = vendors[i]; | |
if(i==1) { | |
propertyUC = propertyUC.slice(0,1).toUpperCase() + propertyUC.slice(1); | |
} | |
if(typeof document.documentElement.style[vendor + propertyUC] !== 'undefined') { | |
return vendor + propertyUC; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment