Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Ibthaj Mansour   on Sep 16 In Asp.net Category.

  
Question Answered By: Jonathan Brown   on Sep 16


<form>
<script language="JavaScript">var preloadImages = new Array(2);
preloadImages[0] = new Image();preloadImages[0].src =
'WebImages/MainSite/Map.jpg';
preloadImages[1] = new Image();preloadImages[1].src =
'WebImages/MainSite/Mandrake_Bldg_2.jpg';
</script>

</form>

</body>
</html>
<img src="/WebApplication124/WebImages/MainSite/Map.jpg" border="0" /><img
src="/WebApplication124/WebImages/MainSite/Mandrake_Bldg_2.jpg" border="0" />

Thats fine ...

if you want the preloaded images to appear in the image  tags then you need to
javascript to tell it to.

Say the images were different ( here they are the same)

Just say you had

<script language="JavaScript">var preloadImages = new Array(2);
preloadImages[0] = new Image();preloadImages[0].src =
'WebImages/MainSite/Mappp2.jpg';
preloadImages[1] = new Image();preloadImages[1].src =
'WebImages/MainSite/Mandrake2.jpg';
</script>

then you wold need to give the img tags an id
<img src="/WebApplication124/WebImages/MainSite/Map.jpg" border="0" id="img1"/>
<img src="/WebApplication124/WebImages/MainSite/Mandrake_Bldg_2.jpg" border="0"
id="img2"/>

and then, to swap them over, javascript something like

function swapimages(){
document.images.img1.src = preloadImages[0].src;
document.images.img2.src = preloadImages[1].src;
}

Share: