jim's jimnasium helps you
Create a Personal Web Page
onMouseOver (and onMouseOut) are predefined JavaScript event handlers. The browser will automatically look for those functions when encountering these reserved words in the HTML tags.
In this example, the image onMouseOver_R.gif (in red) is loaded with the page. When the mouse is passed over the image, a second image, onMouseOver_G.gif, will be loaded at the same place. When the mouse is moved off the image, the red image is reloaded.
To keep the process running fast, all images should be downloaded with the page. As described above, the second image wouldn't be downloaded until the MouseOver event occurred. This could take some time. There are two ways to get the images all loaded. One is to preload the images by adding the JavaScript within the <HEAD> tag for the document:
<SCRIPT LANGUAGE="JavaScript">
<!-- //hide from browsers
a.src = "imageURL.gif"
a.src = "imageURL.gif"
etc. for each image needed
//-->
</SCRIPT>
The other method is to include each image in an IMG tag at the bottom of the page, with the HEIGHT and WIDTH values set to 1, sometimes creating a small dot as the images are loaded. (Like this, for the red and green images:
I made BORDER=1 for the green image to see where it is.)
The HTML used code to perform the rollover above is:
<a href="#"
onMouseOver="document.myImage.src='onMouseOver_G.gif'" <!-- Stay here if you click this (replace # with URL for real link). -->
<!-- Says that the source of the image in the IMG tag named myImage, -->
<!-- when the mouse is over it, is the green one. -->
onMouseOut="document.myImage.src='onMouseOver_R.gif'">
<!-- Says that the source of this image in the IMG tag named myImage, -->
<!-- when the mouse is moved off the image, is the red one. -->
<img src="onMouseOver_R.gif" name="myImage" width=350 height=55 border=0>
<!-- Says that the source of this image when first loaded is the red one. -->
<!-- It also says the name of the image is myImage, so it can be referenced by the scripts. -->
</a>