I would like to flash a success message on my page.
I am using the jQuery fadeOut
method to fade and then remove the element. I can increase the duration to make it last longer, however this looks strange.
What I would like to happen is have the element be displayed for five seconds, then fade quickly, and finally be removed.
How can you animate this using jQuery?
While @John Sheehan's approach works, you run into the jQuery fadeIn/fadeOut ClearType glitch in IE7. Personally, I'd opt for @John Millikin's
setTimeout()
approach, but if you're set on a pure jQuery approach, better to trigger an animation on a non-opacity property, such as a margin.You can be a bit cleaner if you know your margin to be a fixed value:
EDIT: It looks like the jQuery FxQueues plug-in does just what you need:
dansays's answer just doesn't work for me. For some reason,
remove()
runs immediately and the div disappears before any animations happen.The following works, however (by omitting the
remove()
method):I don't mind if there are hidden DIVs on the page (there shouldn't be more than a few anyway).
Update for 1.6.2
Nathan Long's answer will cause the element to pop off without obeying delay or
fadeOut
.This works:
Following on from dansays' comment, the following seems to work perfectly well:
$('#thing') .animate({dummy:1}, 2000) .animate({ etc ... });
The new
delay()
function in jQuery 1.4 should do the trick.