Often times in applications I have a property that would normally .animate(), but every now and then must change instantly. Usually I just set the speed to 0 when doing this, but in an application I'm developing now, my situation is the opposite and performance is much more important. This property is set with .css() on window .resize(), which fires very rapidly (in good browsers anyway), but I'll need to animate this transition sometimes. I'm wondering if it's worth it to use a conditional to set the property with .css() when appropriate and animate when appropriate—or—if .animate() doesn't have much more overhead when the speed is set to 0, I can just do that and save a few lines of code.
+1
A:
There isn't a ton of overhead there, but a more performant option to leaving in your animates and setting new styles instantly is to toggle animations on or off.
http://docs.jquery.com/Effects/jQuery.fx.off
That should detail how to switch animations on or off. If animations are off, then it short circuits most of the overhead of the animate function and just applies the new css.
Alex Sexton
2009-12-04 08:56:32