views:

20

answers:

2

I'm using color plugin (link to google cache, jquery.com currently off) to handle background color animations.

$(".navigation a").hover(
    function(){
        $(this).stop().animate({backgroundColor: black});
    },
    function(){
        $(this).stop().animate({backgroundColor: green});
        $(this).hide();
    }
);

Need to hide current link when animation is finished. Now it hides at once, on mouseout().

What is the solution?

+5  A: 

You need to put the .hide() into the callback function of the .animate() call.

$(this).stop().animate(
    {backgroundColor: green},
    function() {
        $(this).hide();
    }
);
nickf
+2  A: 

By giving .hide() a duration, it will be added to the animation queue.

So you can do this:

$(this).stop().animate({backgroundColor: green}).hide( 0 );
patrick dw
+1 this works great with a "tweenable" animation (background-color isn't one, but that's not your fault). Quite clever, really :-)
Andy E
@Andy E - Thanks. :o) You can animate backgroundColor if you have jQueryUI. http://jsfiddle.net/mfJhH/ Was that what you meant by tweenable?
patrick dw
@patrick: yeah, it was and I didn't know that. It's pretty neat, thanks :-)
Andy E
Oops - I gave the example of the other answer. Here's mine. http://jsfiddle.net/mfJhH/1/
patrick dw