Skip to content

Instantly share code, notes, and snippets.

@dsheiko
Created May 10, 2012 08:10
Show Gist options
  • Save dsheiko/2651827 to your computer and use it in GitHub Desktop.
Save dsheiko/2651827 to your computer and use it in GitHub Desktop.
Allows you to deal with prefixed properties in jQuery
(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