PDA

View Full Version : A little more help with java Please! - Preloading images



mattyjb
01-10-2005, 10:36 PM
Hello all. I have recently just put together a home page in which i have several rollover images for the menu. The script doesnt have any type of preload function:
<a href="index.html" onMouseOver="changer('img1',02)" onMouseOut="changer('img1',01)"><img name="img1" id="img1" border="0" width="178" height="38" src="assets/images/home-up.gif" alt="Home"></a>

running in conjunction with:
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
//JavaScript Simple Image Rollover Code
//copyright daxassist, 2000-2004
//visit http://www.daxassist.com for this and other javascripts with full tutorials.

if(document.images) {
pics = new Array();
pics[01] = new Image();
pics[01].src = "assets/images/home-up.gif";
pics[02] = new Image();
pics[02].src = "assets/images/home-over.gif";
etc etc etc in the head tags

The problem is when i view it in ie6 everytime the cursor goes over the image there a huge delay for the rollover to appear due to the browser busily downloading the rollover image.

how can i get the browser to preload all the roll-over image without having to go and re-code all the buttons?

any help would be great thanks
M@TT

beama
02-10-2005, 08:08 AM
heres a good site for want you want heaps of them google (http://www.google.co.nz/search?hl=en&hs=rym&client=firefox-a&rls=org.mozilla:en-US%3Cimg%20src=%22images/smilies/redface.gif%22%20border=%220%22%20alt=%22%22%20tit le=%22Embarrassment%22%20smilieid=%222%22%20class= %22inlineimg%22%20/%3Efficial_s&q=preload+images+javascript&spell=1)

or this


<script>
<!-- Hide from old browsers
myPict = new Array("../Images/x1.jpg","../Images/x2.jpg","../Images/x3.jpg","../Images/x4.jpg")
end hide -->
</script>


this is not the complete script but it will preload your images Its a snippet from a web site I administer but research those google ones as well