Forum Moderators: not2easy

Message Too Old, No Replies

Image swap doesn't load whole image.

When swaping images the swaped image doesn't load compleatly.

         

MrCup

7:00 am on Mar 6, 2006 (gmt 0)

10+ Year Member



Hi, I've been having a curious problem with my image swapping. I am able to swap the images except the image sometimes only partially loads. Even when it has previously loaded and should be sitting in cache?

The code is nothing fancy.


<SCRIPT LANGUAGE="JavaScript">
<!--
function swapImage(target,location) {
if (document.images) {
document[target].src = location
}
}
//-->
</script>


<a href="javascript:;" onClick="swapImage('bigPic','images/pic1.jpg')"><img src="images/thumbs/pic1thumb.jpg" width="61" height="85" border="0"></a>

Thanks

Phydeaux

4:57 pm on Mar 27, 2006 (gmt 0)

10+ Year Member



While I am by no means an expert in this area, I have experienced a problem similar what you've said. I use "rollovers" for menu buttons and other graphics that change as you pass over them. The problem was that the user never really spent enough time to fully load the graphic leaving a partial graphic in the cache to be shown each time. Only a full page reload would fix it by reloading the cache and even then not every time.

What I did was to pre-load all the images during the page load that I need to use and not wait for the user to activate the graphic download. The page load time is slowed a bit but my graphics aren't real big so it really doesnt show.

Here's the code I use for the preload:

function MM_preloadImages() {
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

<body onLoad="MM_preloadImages('Images/image1.jpg','Images/image2.jpg','Images/image3.jpg','Images/image4.jpg','Images/image5.jpg')">

This may or may not help you but it worked for me :)

Cheers