Click to See Complete Forum and Search --> : Assigning Image Variables


chestertb
10-29-2003, 01:05 AM
Hi all,
My webpage uses little graphics images for buttons, and has the usual rollover effects and other eye candy.

To make the page work, I preload images and then re-assign images like this...

i34a=New Image;i34a.src="images\i34a.gif"
i35a=New Image;i35a.src="images\i35a.gif"
etc... and not... 34 and 35 do not signify that there have been 33 images before.

These images actually form a menu tree and it means that once everythings loaded and assigned, the page is lightning fast.

ITo assign, I have 6 images on the page, labeled btn1 through 6.

Swap images in and out as required by making one variable equal to another as follows;

img1=i34a; //which is assembled according to values returned in an onclick function
imgName = "btn" + y;
imgOn = eval("img"+y '.src');
dr(imgName,imgOn);
document[im].src = io

chestertb
10-29-2003, 01:16 AM
Damn... hate it when I hit "enter" by accident without finishing the post.

Sorry all...
to continue...

The new image gets assigned to the image variable like this...

im1=i34a;
im2=i31a; etc

These values are assembled from variables passed to the function from an onclick event.

I then use
imgOn=eval("im"+y+".src")
imgName="btn"+y
document[imgName].src = imgOn;

And this then displays the correct image in the correct place.

As I said... works a treat, and makes the page VERY fast once it's all loaded.

The images that are used in the initial window draw are pre-loaded in the header, and the images that will be needed later are pre-loaded at the end of the body (or in an onload event... not sure which is better)

When the user clicks the primary button the first time, it takes for what seems like an age to load, even though everything's already preloaded.

Each other button pressed is near instant as you would expect. go to www.hostyourhotel.com to see it working.

I have three questions...

What's the relationship between the order on calls to javascript, and the order that the pages draws itself?

Is assigning the images to variables actually less efficient that simply loading them all up into separate variables in the first place?

and

Anyone got any ideas on why it would take so long to load on first click?