S
sachaburnett
Hi everyone!
I'm new to Javascript and am finding so much useful information on this
group, so thanks to you all!
I have a question about preloading images for onmouseover/out effects
and found so many different ways to do it on the Net but am not sure
about something. Right now I have the following code inside my <head>
tag:
<script language="JavaScript" type="text/JavaScript">
<!-- Preload images
if (document.images) {
imageoff = new Image();
imageoff.src = '/images/imageoff.gif';
imageon = new Image();
imageon.src = '/images/imageon.gif';
}
//--></script>
Then in my html body I have:
<a href="doc/doc.htm"
onmouseover="button1.src=imageon.src;"
onmouseout="button1.src=imageoff.src;">
<img name="button1" src="/images/imageoff.gif">
</a>
Here are my questions:
- I notice that some people use a FOR loop to load mulitple images. Are
there any advantages in using a FOR loop as opposed to using multiple
"new Image ()" and ".src" as I did above?
- Do you need to use onLoad in the <body> tag in order for the images
to properly preload. I see some examples where all the images to be
preloaded are inside a function. So the image preload code I have above
would be inside a function (eg., preLoader() ) and then the <body> tag
would look like <body onload="preLoader();">. Will it still work if I
only have what I have above or do I need to use onload? (my images are
very small and my Internet connection is really fast so I don't don't
if the images are actually being preloaded).
Thanks SO SO SO much!
Sacha
I'm new to Javascript and am finding so much useful information on this
group, so thanks to you all!
I have a question about preloading images for onmouseover/out effects
and found so many different ways to do it on the Net but am not sure
about something. Right now I have the following code inside my <head>
tag:
<script language="JavaScript" type="text/JavaScript">
<!-- Preload images
if (document.images) {
imageoff = new Image();
imageoff.src = '/images/imageoff.gif';
imageon = new Image();
imageon.src = '/images/imageon.gif';
}
//--></script>
Then in my html body I have:
<a href="doc/doc.htm"
onmouseover="button1.src=imageon.src;"
onmouseout="button1.src=imageoff.src;">
<img name="button1" src="/images/imageoff.gif">
</a>
Here are my questions:
- I notice that some people use a FOR loop to load mulitple images. Are
there any advantages in using a FOR loop as opposed to using multiple
"new Image ()" and ".src" as I did above?
- Do you need to use onLoad in the <body> tag in order for the images
to properly preload. I see some examples where all the images to be
preloaded are inside a function. So the image preload code I have above
would be inside a function (eg., preLoader() ) and then the <body> tag
would look like <body onload="preLoader();">. Will it still work if I
only have what I have above or do I need to use onload? (my images are
very small and my Internet connection is really fast so I don't don't
if the images are actually being preloaded).
Thanks SO SO SO much!
Sacha