Created
May 10, 2012 08:10
-
-
Save dsheiko/2651827 to your computer and use it in GitHub Desktop.
Allows you to deal with prefixed properties in jQuery
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( $, document, window ) { | |
var _isPropertySupported = function(prop) { | |
var vendorProp, supportedProp, | |
capProp = prop.charAt(0).toUpperCase() + prop.slice(1), | |
prefixes = [ "Moz", "Webkit", "O", "ms", "Khtml", "Icab" ], | |
div = document.createElement( "div" ); | |
if ( prop in div.style ) { | |
supportedProp = prop; | |
} else { | |
for ( var i = 0; i < prefixes.length; i++ ) { | |
vendorProp = prefixes[i] + capProp; | |
if ( vendorProp in div.style ) { | |
supportedProp = vendorProp; | |
break; | |
} | |
} | |
} | |
div = null; | |
$.support[prop] = supportedProp | |
return supportedProp; | |
}, | |
_hookProp = function(prop) { | |
// Implements cssHooks (http://api.jquery.com/jQuery.cssHooks/) | |
var propPrefixed = _isPropertySupported(prop); | |
if (propPrefixed && propPrefixed !== prop) { | |
$.cssHooks[prop] = { | |
get: function( elem, computed, extra ) { | |
return $.css(elem, propPrefixed); | |
}, | |
set: function( elem, value) { | |
elem.style[propPrefixed] = value; | |
} | |
}; | |
} | |
}; | |
// Add here any properties you need | |
_hookProp("transition"); | |
_hookProp("transform"); | |
// Check $('#sample').css("transition", "scale(2)"); | |
})( jQuery, document, window ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment