0

I was trying to use spinner images while the image is loading, and then I saw this thread:

How to show a spinner while loading an image via JavaScript

I did quite some search but I still don't quite understand in the accepted answer why put objImagePreloader.onload=function(){}; in another onloadfunction or how exactly it works. Could someone explain to me? It might be obvious but I am rather new to web design and any help will be very much appreciated.

Thanks, YL

Community
  • 1
  • 1
YonL
  • 39
  • 1
  • 6

1 Answers1

0

Whenever You create/preloading an image the onload function stands for: image has been loaded....now You can elaborate So in your case setting objImagePreloader.onload=function(){}; means do nothing on image just loaded because you will use your callback function to do the task.

Hope this answer be enough clear.

by gm

gaetanoM
  • 41,594
  • 6
  • 42
  • 61
  • Yeah...I got what you mean, but why is it necessary since the callback will be called anyways? I don't understand why the `if({}` and `else{}` looks exactly the same.... – YonL Aug 03 '14 at 22:51