Page 1 of 1

Need help understanding/improving this javascript

Posted: Sun Jul 31, 2005 10:09 am
by charp
The following script drives a sort of slide show where the user moves the mouse over a thumbnail to see a larger version of that image with an appropriate caption:

Code: Select all

<script language=JavaScript>
<!--
// Courtesy of http://simplythebest.net/scripts/
function changetext(html){
document.getElementById('DESCRIPTION2').innerHTML=html
}

/*JavaScript Kit (http://javascriptkit.com)*/
function changeimage(towhat,url){
if (document.images){
document.images.targetimage.src=towhat.src
}
}

var myimages=new Array()
var gotolink=&quote;#&quote;
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages&#1111;i]=new Image()
myimages&#1111;i].src=preloadimages.arguments&#1111;i]
}
}
preloadimages(&quote;58011/58011-0.jpg&quote;,&quote;58011/58011-1.jpg&quote;,&quote;58011/58011-2.jpg&quote;)
//-->
</script>
This next bit is the HTML link for the thumbnail, which calls the necessary functions from the JavaScript.

Code: Select all

<a href=&quote;58011/58011L-0.jpg&quote; onMouseover=&quote;changeimage(myimages&#1111;0],this.href);
changetext('Front view of home with new paint.')&quote; target=&quote;_blank&quote;>
<img class=&quote;rentpic&quote; src=&quote;58011/58011-0.jpg&quote; width=&quote;50&quote; height=&quote;38&quote; border=&quote;0&quote; /></a>
Finally, here is the target for the caption and the larger image:

Code: Select all

<div id=&quote;DESCRIPTION2&quote; style=&quote;height: 2.5em; width:300px;text-align:left;&quote;>
Front view of home with new paint.</div>
<img class=&quote;rentpic&quote; src=&quote;58011/58011-0.jpg&quote; name=&quote;targetimage&quote; width=&quote;300&quote; height=&quote;225&quote;>
In order to make the script more portable and easier to update, I'd like to make number of changes. For now, however, I'd like to understand a few parts of this script.

In the function changeimage(towhat,url), is the second argument (url) being used at all? If I remove it, the script still functions. If it is not used/required, can I also remove 'this.href' from the 1st line in the second bit of code? Well, this too I have done and it works, so I guess my question is really this: have I created any problems by removing those parts of this script?

Lastly, does line 16 (var gotolink="#") from the first code snippet have any function here? Can I remove that line as well without fear of causing a problem in some browsers?

Thanks in advance!

Re: Need help understanding/improving this javascript

Posted: Sun Jul 31, 2005 2:35 pm
by feyd
charp wrote:In the function changeimage(towhat,url), is the second argument (url) being used at all? If I remove it, the script still functions. If it is not used/required, can I also remove 'this.href' from the 1st line in the second bit of code? Well, this too I have done and it works, so I guess my question is really this: have I created any problems by removing those parts of this script?
the function does not look at, or care what url is defined as.
Lastly, does line 16 (var gotolink="#") from the first code snippet have any function here? Can I remove that line as well without fear of causing a problem in some browsers?
line 16 does not appear to be used in the code you posted.