2

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.