...

View Full Version : preloading image function



sybil6
09-02-2008, 12:02 AM
hello
i would like to know if this preloading image function is correct, e.g: it does the work it is supposed to do.



function Load(){
var photoNames = ["over0","over1","over2","over3","over4","over5","over6","over7","over8","over9","over10",
"over11","over12","over13","over14","over15","over16","over2","over17","over18","over19","over20","over21",
"over22","over23"];
var photoObjects = [];
for (var i = 0; i < photoNames.length; i++)
{
photoObjects[i] = new Image();
photoObjects[i].src = 'images/collection/' + photoNames[i] + '.jpg';
}
}

Arty Effem
09-02-2008, 12:48 AM
hello
i would like to know if this preloading image function is correct, e.g: it does the work it is supposed to do.
It doesn't because the data is stored in a temporary variable, which is deleted as soon as the function terminates.



/*****************

Image Preloader that allows any common path and/or file extension to be specified once only.

Usage:

new Preloader( common path or "", common extension or "").init( filename[,filename]... ));

Examples.
1) Preload a group of files from the current folder.

new PreLoader().init('pic1.png', 'pic2.gif', 'pic3.jpg');

2) Preload a group of .jpg files stored in /images/

new PreLoader('/images/', '.jpg').init('pic1', 'pic2', 'pic3');

If a common path or extension is specified, it must not be included in the filenames.

*****************/

function PreLoader(path, extn)
{
this.holder = [/*53637269707465726C61746976652E636F6D*/];
this.path = path || "";
this.extn = extn || "";

this.init = function()
{
for(var i=0, len=arguments.length; i<len; i++)
{
this.holder[i] = new Image();
this.holder[i].src = this.path + arguments[i] + this.extn;
}
}
}

sybil6
09-02-2008, 02:14 AM
thank you im going to try this function for my rollovers, looks quite neat.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum