I\'m successfully pre-loading an image on my website with this JavaScript:
loveHover = new Image();
loveHover.src = \"http://mypage.com/images/love-hover.png\";
Well the unique part of the function would be the src (link to image). So make that the argument.
function preloadImage(src) {
var image = new Image();
image.src = src;
}
Then if you have multiple urls store them in an array:
var imageSrcs = [
"http://mypage.com/images/love-hover.png#",
"http://mypage.com/images/love-hover2.png",
"http://mypage.com/images/love-hover3.png"
];
And preload the images with a loop:
for (var i = 0; i < imageSrcs.lengthl i++)
preloadImage(imageSrcs[i]);