Wednesday, July 13, 2005

Reloading images without flicker

From Here
Finally found how to refresh an image in a document without making the old image disappear while the new one loads. I know I'm going to forget this if I don't write it down, so...

foo = new Image();
foo.src = url_of_new_image;
foo.onerror = function_to_call_if_download_fails;
foo.onload = function_to_call_when_download_finishes;

Then stash foo away somewhere, and when the foo.onload function gets called, copy foo.src over to the image you want to refresh.