JavaScript - How To Precache Imgs?
Hi all.
I would like to precache my menu imgs cos of rollover delay. Tried this way, Is it right? Code: <script type="text/javascript"> var offImgArray = new array(); offImgArray["imgname2"].src ="images/navbtn/offbtn_2.gif"; offImgArray["imgname3"].src ="images/navbtn/offbtn_3.gif"; offImgArray["imgname4"].src ="images/navbtn/offbtn_4.gif"; offImgArray["imgname5"].src ="images/navbtn/offbtn_5.gif"; // same for on images? // code here function linkOver(link) { var image = link.getElementsByTagName("IMG")[0]; image.src = image.src.replace("offbtn_2.gif","onbtn_2.gif"); image.src = image.src.replace("offbtn_3.gif","onbtn_3.gif"); image.src = image.src.replace("offbtn_4.gif","onbtn_4.gif"); image.src = image.src.replace("offbtn_5.gif","onbtn_5.gif"); // other imgs here } Edit. I'm missing smthg cos I get error array is nul etc low tech Similar TutorialsIn firefox Images 1 2 & 3 won't swap and in IE the img src(not PhotoBig) wont show pics 1 2 & 3 any reason why? I'm new to javascript so its probably a dumb reason? Please help if you can. Code: <script type="text/javascript"> function update(url,index,isSuper) { document['PhotoBig'].src=url; } </script> Code: <img src="graphics/travel/big/keysfish1.gif" name="PhotoBig" style="border:1px solid black"> <table> <tr> <td> <a onMouseOver="update('graphics/travel/big/keysfish1.gif', 0, false); return false;"> <img src="graphics/travel/thumbnails/keysfish1.gif" style="border:1px solid black"> </a> </td> <td> <a onMouseOver="update('graphics/travel/big/keysfish2.gif', 1, true); return false;"> <img src="graphics/travel/thumbnails/keyfish2.gif" style="border:1px solid black"> </a> </td> <td> <a onMouseOver="update('graphics/travel/big/keysfish3.gif', 2, true); return false;"> <img src="graphics/travel/thumbnails/keyfish3.gif" style="border:1px solid black"> </a> </td><td> <a onMouseOver="update('graphics/travel/big/keysfish4.gif', 3, true); return false;"> <img src="graphics/travel/thumbnails/keyfish4.gif" style="border:1px solid black"> </a> </td> </tr> <tr> <td colspan="4" style="text-align: center; font: .8em 'Comic Sans MS', Arial;"> Move the cursor over the images/picture you wish to preview. </td> </tr> <tr> <td> <a onMouseOver="update('graphics/travel/big/keysturtle1.gif', 4, true); return false;"> <img src="graphics/travel/thumbnails/keysturtle1.gif" style="border:1px solid black"> </a> </td><td> <a onMouseOver="update('graphics/travel/big/tyleranthony.gif', 5, true); return false;"> <img src="graphics/travel/thumbnails/tyleranthony.gif" style="border:1px solid black"> </a> </td> <td> <a onMouseOver="update('graphics/travel/big/uwdiver1.gif', 6, true); return false;"> <img src="graphics/travel/thumbnails/uwdiver1.gif" style="border:1px solid black"> </a> </td><td> <a onMouseOver="update('graphics/travel/big/uwlou.gif', 7, true); return false;"> <img src="graphics/travel/thumbnails/uwlou.gif" style="border:1px solid black"> </a> </td> </tr> </table> Hi all If I pre-cache imgs like this ... (10 in all) Code: <head> <script type="text/javascript"> PreImage1= new Image(width,height); PreImage1.src = "images/navbtn/onbtn_1.gif"; PreImage2 = new Image(width,height); PreImage2.src = "images/navbtn/onbtn_2.gif"; PreImage3= new Image(width,height); PreImage3.src = "images/navbtn/offbtn_1.gif"; PreImage4 = new Image(width,height); PreImage4.src = "images/navbtn/offbtn_2.gif"; </script> Will imgs be read from cache if I then do this?... or have I missed smthg? Code: <body> <img src="images/navbtn/offbtn_1.gif" onmouseover=this.src="images/navbtn/onbtn_1.gif" onmouseout=this.src="images/navbtn/offbtn_1.gif" alt="" /> </div> low tech Hi all Is there a way to get the image(s) to load into the table after the page has loaded instead of the way I have it now? I have 4 tabs, but I would like the imgs in tabs 2,3,4 to load after page load. Example of how the tabs look. Code: <div class="tabbertab"> <h2>Australia_____</h2> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFCC"> <caption class="highlight_Red">澳洲 Australia </caption> <tr> <td><a href="pages/promotion.html#aus_ACE" rel="nofollow" target="_blank"><img src="pages/images/Pics/AUS/ace.jpg" alt="ACE / ATTC" width="110" height="69" border="0" align="left" class="ozimg_L"/> ...a few more images etc the other tabs look the same. LT |