Comments on this code?... and one question

I

Ivan Marsh

I've been meaning to write an image swapper like this for a while and I
finally got it to work the way I want it to. I was wonder what you folks
think of it.

Also, the preloadimages() function isn't necessary for the image swapping
functions to work but I'm wondering if it's doing anything
at all to speed up image swap when the page is loaded for the first time.

Am I right in assuming that once these images are cached that the
functions will be pulling them from cache?

<SCRIPT LANGUAGE='JavaScript'>

var myimages = new Array();

function preloadimages() {

var imagelist = new Array(
"/test/imageswap/images/test-out.gif",
"/test/imageswap/images/test-over.gif",
"/test/imageswap/images/test-click.gif",
"/test/imageswap/images/test2-out.gif",
"/test/imageswap/images/test2-over.gif",
"/test/imageswap/images/test2-click.gif"
);

for (i=0; i < imagelist.length; i++) {
myimages = new Image();
myimages.src = imagelist;
}
}

preloadimages();

function imgonmouseover(currentimage) {
currentimage.src = currentimage.src.substring(0, currentimage.src.lastIndexOf('-') + 1) + 'over' + currentimage.src.substring(currentimage.src.lastIndexOf('.'));
}

function imgonmouseout(currentimage) {
currentimage.src = currentimage.src.substring(0, currentimage.src.lastIndexOf('-') + 1) + 'out' + currentimage.src.substring(currentimage.src.lastIndexOf('.'));
}

function imgonclick(currentimage) {
currentimage.src = currentimage.src.substring(0, currentimage.src.lastIndexOf('-') + 1) + 'click' + currentimage.src.substring(currentimage.src.lastIndexOf('.'));
}


</SCRIPT>

<HTML>
<BODY BGCOLOR='BLACK'>
<FONT COLOR='WHITE'>
<CENTER>
<IMG BORDER='0' NAME='test' SRC='/test/imageswap/images/test-out.gif' ONMOUSEOVER='imgonmouseover(this)' ONMOUSEOUT='imgonmouseout(this)' ONCLICK='imgonclick(this)'>
<P>
<IMG BORDER='0' NAME='test2' SRC='/test/imageswap/images/test2-out.gif' ONMOUSEOVER='imgonmouseover(this)' ONMOUSEOUT='imgonmouseout(this)' ONCLICK='imgonclick(this)'>
</CENTER>
</BODY>
</HTML>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top