Closed Thread Icon

Preserved Topic: preload question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18259" title="Pages that link to Preserved Topic: preload question (Page 1 of 1)" rel="nofollow" >Preserved Topic: preload question <span class="small">(Page 1 of 1)</span>\

 
hecster2k
Nervous Wreck (II) Inmate

From: sj, ca, usa
Insane since: Feb 2002

posted posted 04-03-2002 23:37

i have a preloader that says:

code:
if (document.images) 
preloaded_image = new Image(155 ,24); sidenav_r02_c2_f1.src = "images/sidenav_r02_c2.gif";



question is, is there any particular reason why you would assign it to "preloaded_image"? or could u just say

code:
for (i=0;i<images.length;i++) {
img[i] = new image();
img[i].src=image+i+".gif";
}



it's just that i was tasked to clean up some Dreamweaver code, and it's a mess.... and it has preloaders up the yin-yang and a bunch of overly complicated code for simple mouseovers.... help!

"there has to be a solution."

[This message has been edited by hecster2k (edited 04-04-2002).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-04-2002 00:00

hokay these are both actually a bit flawed.

This (cleaned a bit for readability):
if (document.images) {
preloaded_image = new Image(155 ,24);
sidenav_r02_c2_f1.src = "images/sidenav_r02_c2.gif";
}

should actually be

if (document.images) {
preloaded_image = new Image(155 ,24);
preloaded_image.src = "images/sidenav_r02_c2.gif"; // see the preloaded image part?
}

using an array is fine but you have to declare the array and use that.

imgs = new Array;
for (i=0;i<images.length;i++) {
imgs[i] = new image();
img[i].src=image+i+".gif";}
}



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

hecster2k
Nervous Wreck (II) Inmate

From: sj, ca, usa
Insane since: Feb 2002

posted posted 04-04-2002 00:21

oops, thats what i meant ...

regarding the actual code, can you explain to me exactly what happens when you preload these? is the variable (in this case "preloaded_image") only used for caching purposes in that particular line of code, and not used anywhere else? or is it referenced in different bits of code? i've always been in the dark about this ....

thanks for your expert tutelage!

"there has to be a solution."

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-04-2002 00:38

yeah it's just a placeholder. It gets the image into cache for quick image swaps.

Elsewhere in the code what it would be refrenced for an imageswap most usually.
say you have an image somewhere named "myImg" like so

<img src="whatever.gif" name="myImg">

Then you can change the source of that image like this.

myImg.src = imgs[1].src;

and since you preloaded the image it grabs the image from the browser cache instead of from the server, you get a nice snappy rollover. Without the preload you could have something like this

myImg.src = "whatever.gif";

but the image is going to be downloaded during the rollover (you can watch this on your status bar);

The irony of preloading though is that though it speeds up your rollover you actually have to load 3 images. The img that gets loaded in the image tag, the over state image and the default image again.





.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

« BackwardsOnwards »

Show Forum Drop Down Menu