Posted By

createinside on 01/29/10


Tagged

preload images preloader preloading


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

kele5240
wirenaught


Image preloader


 / Published in: JavaScript
 

URL: http://perishablepress.com/press/2009/12/28/3-ways-preload-images-css-javascript-ajax/

Der er flere tilpassede løsninger på den adresse, som er angivet.

  1. function preloader() {
  2. if (document.images) {
  3. var img1 = new Image();
  4. var img2 = new Image();
  5. var img3 = new Image();
  6.  
  7. img1.src = "http://domain.tld/path/to/image-001.gif";
  8. img2.src = "http://domain.tld/path/to/image-002.gif";
  9. img3.src = "http://domain.tld/path/to/image-003.gif";
  10. }
  11. }
  12. function addLoadEvent(func) {
  13. var oldonload = window.onload;
  14. if (typeof window.onload != 'function') {
  15. window.onload = func;
  16. } else {
  17. window.onload = function() {
  18. if (oldonload) {
  19. oldonload();
  20. }
  21. func();
  22. }
  23. }
  24. }
  25. addLoadEvent(preloader);

Report this snippet  

You need to login to post a comment.