0

I want to be able to add a css property\value using jquery but I want to wait until the animation has been made first then I want the css to remove the animation by setting its display value to none.

This is a snippet of my code.

**Jquery**
 $(".filled-rectangle").animate(); 
 $(".filled-rectangle").css('display', 'none'); 
1
  • post html code part as well, and what does your code do does it fail? Commented Dec 2, 2012 at 13:02

1 Answer 1

2

You can use the .promise() and .done() methods to add actions at the end of the current animation queue:

$(".filled-rectangle").animate().promise().done(function() {
    $(".filled-rectangle").css('display', 'none');
});

This is very useful if you want to allow other code to add callbacks to be called once the animation is done, since you can return the promise returned by the .promise() method.

Or, you can add callbacks into the animation queue itself with .queue():

$(".filled-rectangle").animate().queue(function(next) {
    $(".filled-rectangle").css('display', 'none');
    next();
});
Sign up to request clarification or add additional context in comments.

3 Comments

I mean using either of promise and queue
There are examples of both on the two documentation pages I linked to, have a look at them. (The one one the promise page is quite far down.) If the examples don't make sense, I might be able to help more.
Please do a fiddle instead. I checked it but it will not work

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.