Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preload Images from External Source

Status
Not open for further replies.

RamDje

Programmer
Apr 3, 2003
23
US
Hello all,

Is it possible to preload images from an external source....like a xxx.js file. Basically I have a banner which has rollovers. This will be used on all pages of the site. I would rather preload the images associated with the rollover from an external source. Would this be possioble without having to use the onLoad in the body tag?

Any help would be great. Thanks in advance.

-RRD

RRD
 
RRD,

If you include the JS file, you can get away without placing an onload event on the body. Just don't place your preload code in a function, and it will automatically run.

Better still, place your preload code in a function, and call that in the script... So your JS file would contain:

Code:
     function preLoadImages()
     {
          var myImgCache = new Array();
          myImgCache[myImgCache.length] = new Image();
          myImgCache[myImgCache.length-1].src = 'ibble.jpg';
          myImgCache[myImgCache.length] = new Image();
          myImgCache[myImgCache.length-1].src = 'wibble.jpg';
          myImgCache[myImgCache.length] = new Image();
          myImgCache[myImgCache.length-1].src = 'bibble.jpg';
     }
     preLoadImages();

Hope this helps,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top