1

I have a page where I basically want an element to 'blink' for a certain amount of time and then go back to its initial state. Using jquery UI you can animate the addClass() and removeClass() methods:

 $this.addClass('success', 400);

and then

 setTimeout(function(){                 

     $this.removeClass('success', 400);

 }, 1000);

where the class 'success' has a

background-color: green 

The first works. But the removeClass() inside the setTimeout simply removes the class without doing ANY animation. What can this be caused by?

3
  • 1
    Can you show how you are assigning $this? I've tested this and it seems fine. My code is slightly different than yours tho. Fiddle here Commented Jun 29, 2012 at 15:18
  • 2
    Like the above, I too cannot replicate this. Commented Jun 29, 2012 at 15:19
  • mmmh.... ok then it's gotta be a CSS conflict somewhere. Thanks anyway. Commented Jul 1, 2012 at 10:08

1 Answer 1

4

Perhaps you'd use such a helpful method as .delay() ?

$('button#test_add').click(function() {
    $('#content').addClass('success', 400);
});

$('button#test_remove').click(function() {
    $('#content').delay(1000).removeClass('success', 400);
});

And here's a JSFiddle to play with.

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

2 Comments

this is a better approach than directly touch setTimeout
I appreciate the suggestion of using delay instead of setTimeout!

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.