preload
Form Calculation Onloading functions
Feb 27

A very simple way to load the images into the browsers cache so when they are displayed they will not have to load the file and create a delay in the browser.

// Initiate the image count variable
var imageCount = 0;
// create an array to contain the preloaded image files
var preloadImages = new Array();

// Main function to load new image into browser
function preload(imageFile)
{
imageCount++;
preloadImages[imageCount] = new Image();
preloadImages[imageCount].src = imageFile;
}

// Basic function to load the images when the browser has loaded the webpage.
window.onload = function() {
preload('images/1.jpg');
preload('images/2.jpg');
preload('images/3.jpg');
preload('images/4.jpg');
preload('images/5.jpg');
}

Leave a Reply

 
 
Please enter the word above into the box below, the word is not case sensitive.
 
If you have trouble reading the word above then click here to load a new word.
Security word: