Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preloading Images + MouseOver

Status
Not open for further replies.

Neily

Programmer
Jul 27, 2000
342
GB
I have some code in JavaScript but I don't really understand how it works so can't improve it as it is a little on the lage side.

Basically I want to have the images preload so when the mouse goes over an image displayed it is already there to display and won't have to wait for it to load. Ther is about 20 of these and I don't want to have lots of typing of filenames etc to get it to work. A simple function in vbScript to do it all and then just have the name of an variable or like in the 'onmouseover=' pat of IMG tag would be ideal.

ManyThanks
Neil
 
U have to use img tag with style="visibility:hidden" and then use this img to your onmouseover event... ________
George, M
 
Thanks.

Could you give me an example as I can't seem to get it to work on my system, maybe I am doing something wrong.
 
try this...
should look something like this...

Code:
<html>
<body onload=&quot;enbleMenu();&quot;>
<script language=&quot;javascript&quot;>
var enabled=false;
function enbleMenu()
{
  enabled=true;
};
</script>
<img src=&quot;filepath1&quot; name=name1 id=name1 style=&quot;visibility:hidden&quot;>
<img src=&quot;filepath2&quot; name=name2 id=name2 style=&quot;visibility:hidden&quot;>
.....
<img src=&quot;filepath1&quot; onmouseover=&quot;if(enabled) this.src=name2.src;&quot; onmouseout=&quot;this.src=filepath1;&quot;>
</body>
</html>
________
George, M
 
This would work as well, place it inside your <head> tag.

<script LANGUAGE=&quot;JavaScript&quot;>
<!--
homeoff = new Image();
homeoff.src = &quot;images/home-off.gif&quot;;
homeon = new Image();
homeon.src = &quot;images/home-on.gif&quot;;
// -->
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top