Image Preloader Script - Lite Version

essential 0 Tallied Votes 199 Views Share

This script simply preload's images inside (x)HTML document.

<<<INSTRUCTION>>>

— Simply attached these preloader.js in your document, were you want your images to be preloaded.

— You can simply referenced it using <script type="text/javascript" src="path/preloader.js"></script> block.

— if you have any suggestions, comments or request, please feel free to post it below.

essential

/***********************************************
Developed By DANIuser : essential

* Title : Image Preloader Script -
* Created : April 24th, 2009
* This notice MUST stay intact for use
* http://www.daniweb.com/forums/member383844.html 
***********************************************/

var preload, myImages; 
var img, iLen, x, y;
var isImage = [ {
iSrc : [],
iPath : [] }];

preload = (function() {
myImages = function() {
   if ( document.images ) {
   img = ( document.getElementsByTagName ) ? document.getElementsByTagName("img") : document.images;
   iLen = img.length;
      try {
         for ( x = 0; x < iLen; x++ ) {
         isImage[0].iSrc[x] = new Image();
            for ( y in isImage[0].iSrc ) {
            isImage[0].iPath[y] = img[y].src;
            }
         isImage[0].iSrc[x].src = isImage[0].iPath[x];
         img[x].src = isImage[0].iSrc[x].src;
         } return true;
      }       
      catch( e ) {
      (( e.description ) ? alert( e.description ) :  alert( e.message ));
      } 
   } return false;
}; 
   return {
myImages : myImages 
   };
}()); // Preloaded Images

window.onload = preload.myImages;