Phillip Pearson - Second p0st

tech notes and web hackery from the guy that brought you bzero, python community server, the blogging ecosystem, the new zealand coffee review and the internet topic exchange

2005-7-13

Reloading images without flicker

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.