Skip to content

Instantly share code, notes, and snippets.

@frostney
Created April 30, 2012 19:05
Show Gist options
  • Save frostney/2561433 to your computer and use it in GitHub Desktop.
Save frostney/2561433 to your computer and use it in GitHub Desktop.
Small jQuery plugin for using CSS3 properties with vendor prefixes. Also includes functions for scaling and rotating.
(function($) {
var vendorPrefix = ['webkit', 'o', 'ms', 'moz'];
$.fn.vendorProperty = function(property, argument) {
var self = this;
self.css(property, argument);
$.each(vendorPrefix, function(index, value) {
self.css('-' + value + '-' + property, argument);
});
}
$.fn.transform = function(transformArgument) {
if (typeof transformArgument === "undefined") {
return;
}
this.vendorProperty('transform', transformArgument);
}
$.fn.transformOrigin = function(originX, originY) {
var originArgument = originX + ' ' + originY;
this.vendorProperty('transform-origin', originArgument);
}
$.fn.scale = function(scaleX, scaleY) {
if (typeof scaleY === "undefined") {
scaleY = scaleX;
}
this.transform('scale(' + scaleX + ', ' + scaleY + ')');
}
$.fn.rotate = function(angle) {
if (typeof angle !== "number") {
return;
}
this.transform('rotate(' + angle + 'deg)');
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment