Forum Moderators: open

Message Too Old, No Replies

how to adjust this detail

         

KSi_Europe

9:21 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



I have this code and works fine, but the images must be in the same folder as the index page. I can't figure out how to make it work if I put the pictures in an other folder, how to preload them. Can somebody help me, I'm sure it's a small detail but I'm a beginner here so I can't find it.

That's the code:

<script>
function changeimage(towhat,url){
if (document.images){
document.images.targetimage.src=towhat.src
gotolink=url
}
}
function warp(){
window.location=gotolink
}

</script>
<script language="JavaScript1.1">
var myimages=new Array()
var gotolink="#"

function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}

preloadimages("pic1.gif","pic2.gif","pic3.gif","pic4.gif","pic5.gif")
</script>

kaled

12:10 am on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm half asleep but I think I spotted a mistake.

function warp(){
window.location.href=gotolink
}

You could also try the following

function preloadimages(dir){
for (i=1; i < arguments.length; i++){
myimages[i] = new Image()
myimages[i].src = dir + '/' + arguments[i]
}}

The first param is now the directory and the remaining params are filenames within that directory.

Kaled.

KSi_Europe

8:55 am on Nov 22, 2004 (gmt 0)

10+ Year Member



I don't know, must be something wrong or it's me, but it doesn't work.
I think I will leave my photos where they are, it a little crowdy but at least it works.

Thank you very much anyway, I appreciated that.

Bernard Marx

9:27 am on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't give up now, you're so close.

With Kaled's code, you just need to specify the path to the directory with the first argument (this is why the loop counter starts at 1, so as to miss it out).

eg:

preloadimages("../images/","pic1.gif","pic2.gif","pic3.gif","pic4.gif")

KSi_Europe

12:53 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



I'm sorry but I still can't fix it.
So supposing the folder is "images" like you wrote, what would be the entire code like, can you just correct that one i wrote above? Because I don't know now or it must be somewhere "dir" or "images" or maybe something else somewhere...I tried in many ways but no success

kaled

2:23 pm on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should change the first line of the function I suggested as indicated below.

for (var i=1; i < arguments.length; i++){

After that assuming that you have images located in a folder /images/test

you would preload images thus

preloadimages('/images/test','pic1.gif','pic2.gif','pic3.gif');

If that doesn't work, you need to open a javascript console to see if the script is generating errors. I prefer Opera for debugging scripts but Firefox is ok.

Kaled.