Forum Moderators: open

Message Too Old, No Replies

preloading images

         

Sothpaw

2:17 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



i have this clause in my JS
var preloadimg="yes"
it used to say no... but i changed it because i want my images to preload... but it still doesn't seem to preload.
does something else control image preloading for rollovers?

Bernard Marx

2:29 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We will need to see the preloading script. Preloading isn't built-in.

Sothpaw

2:30 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



would that be this part...?
if (preloadimg=="yes"){
for (x=0; x<dynimages.length; x++){
var myimage=new Image()
myimage.src=dynimages[x][0]
}
}

penders

3:35 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, that looks like it... but it is also dependant on array called dynimages being defined somewhere which contains a list of every image you want to preload. It looks as if the array (a multi-dimensional array [][]) probably contains more than just the filename...?

Sothpaw

4:07 pm on Jul 6, 2007 (gmt 0)

10+ Year Member



is this what you need to see...?

var dynimages=new Array()
dynimages[1]=["001.jpg", ""]
dynimages[2]=["002.jpg", ""]
dynimages[3]=["003.jpg", ""]
etc.

RonPK

4:51 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that looks like it... The script might break on the item
dynimages[0]
not being defined. To circumvent that problem, replace the line

for (x=0; x<dynimages.length; x++){

with

for (x in dynimages) {

Bernard Marx

5:15 pm on Jul 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not..

for (x=1; x<dynimages.length; x++){

or re-index the array to start at [0].

for .. each should be avoided on objects that we don't know more about. The script may have assigned dynimages (or even Array.prototype) a property.

Sothpaw

3:08 pm on Jul 9, 2007 (gmt 0)

10+ Year Member



it seems to help... but doesn't seem to completely pre-load.
i've attached my full JS code and hopefully i missed something that will make it fully pre-load.
are there any websites with a good working preload function that i could examine?

var dynimages=new Array()
dynimages[1]=["001.jpg", ""]
dynimages[2]=["002.jpg", ""]
dynimages[3]=["003.jpg", ""]

var preloadimg="yes"

var optlinktarget=""

var imgborderwidth=0

if (preloadimg=="yes"){
for (x=1; x<dynimages.length; x++){
var myimage=new Image()
myimage.src=dynimages[x][0]
}
}
function returnimgcode(theimg){
var imghtml=""
if (theimg[1]!="")
imghtml='<a href="'+theimg[1]+'" target="'+optlinktarget+'">'
imghtml+='<img src="'+theimg[0]+'" width="100%" border="'+imgborderwidth+'">'
if (theimg[1]!="")
imghtml+='</a>'
return imghtml
}
function modifyimage(loadarea, imgindex){
if (document.getElementById){
var imgobj=document.getElementById(loadarea)
if (imgobj.filters && window.createPopup){
imgobj.style.filter=filterstring
imgobj.filters[0].Apply()
}
imgobj.innerHTML=returnimgcode(dynimages[imgindex])
imgobj.filters[0].Play()
return false}}

mehh

4:09 pm on Jul 9, 2007 (gmt 0)

10+ Year Member



what is this script meant to do. it looks like some sort of slideshow

Sothpaw

4:28 pm on Jul 9, 2007 (gmt 0)

10+ Year Member



on mouseover of the icons, the main image changes.
it's a portfolio of images.

Sothpaw

8:01 pm on Jul 9, 2007 (gmt 0)

10+ Year Member



never mind.
i got my answer from webdeveloper.com
thanks anyway.