Created
October 23, 2010 02:32
-
-
Save paulirish/641692 to your computer and use it in GitHub Desktop.
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
// allow $('elem').css({ 'left' : '+=10px' }); | |
// so you dont need to do: | |
// $('elem').animate({ 'left' : '+=10px' }, 0); | |
// by paul irish | |
// for ralph holzmann | |
// http://github.com/paulirish/lazyweb-requests/issues#issue/10 | |
(function($, oldcss){ | |
// magic from the core. | |
var rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/; | |
$.fn.css = function(obj, val){ | |
var parts = rfxnum.exec(val), | |
that = this; | |
if ($.isPlainObject(obj)){ | |
$.each(obj, function(k, v){ | |
$(that).css(k, v); | |
}); | |
// here's the magic. | |
} else if (val && parts && parts[1]) { | |
var end = parseFloat(parts[2]) | |
return oldcss.call(this, obj, function(index, currentValue){ | |
return ((parts[1] === "-=" ? -1 : 1) * end) + parseFloat(currentValue); | |
}); | |
// no fancypants | |
} else { | |
return oldcss.apply(this, arguments); | |
} | |
return this; | |
}; | |
})(jQuery, jQuery.fn.css); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That essentially what i'm doing. :)