How can I fade one image into another with jquery? As far as I can tell you would use fadeOut, change the source with attr() and then fadeIn again. But this doesn’t seem to work in order. I don’t want to use a plugin because I expect to add quite a few alterations.
Thanks.
In the simplest case, you’ll need to use a callback on the call to fadeOut().
Assuming an image tag already on the page:
You pass a function as the callback argument to
fadeOut()that resets thesrcattribute and then fades back usingfadeIn():For animations in jQuery, callbacks are executed after the animation completes. This gives you the ability to chain animations sequentially. Note the call to
load(). This makes sure the image is loaded before fading back in (Thanks to Y. Shoham).Here’s a working example