Need help understanding/improving this javascript
Posted: Sun Jul 31, 2005 10:09 am
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:
This next bit is the HTML link for the thumbnail, which calls the necessary functions from the JavaScript.
Finally, here is the target for the caption and the larger image:
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!
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="e;#"e;
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimagesїi]=new Image()
myimagesїi].src=preloadimages.argumentsїi]
}
}
preloadimages("e;58011/58011-0.jpg"e;,"e;58011/58011-1.jpg"e;,"e;58011/58011-2.jpg"e;)
//-->
</script>Code: Select all
<a href="e;58011/58011L-0.jpg"e; onMouseover="e;changeimage(myimagesї0],this.href);
changetext('Front view of home with new paint.')"e; target="e;_blank"e;>
<img class="e;rentpic"e; src="e;58011/58011-0.jpg"e; width="e;50"e; height="e;38"e; border="e;0"e; /></a>Code: Select all
<div id="e;DESCRIPTION2"e; style="e;height: 2.5em; width:300px;text-align:left;"e;>
Front view of home with new paint.</div>
<img class="e;rentpic"e; src="e;58011/58011-0.jpg"e; name="e;targetimage"e; width="e;300"e; height="e;225"e;>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!