|
Blue Star Gold Star Green Star Purple Star Silver Star Yellow Star |
![]() |
This example uses the onMouseOver event-handler and the function "MM_swapImage()" to display (swap) colored stars in place of an initial image of a solid white square. The onMouseOut event-handler and the function "MM_swapImgRestore()" restore (swap back) the solid white square.
The HTML border attribute of the image <img> tag has been set to 1 (border=1) so that a thin line is shown around the image space, simply to make its location visible. The onMouseOver event-handler calls the MM_swapImgRestore function with information which changes the name of the image displayed. For example, when the mouse pointer is passed over the "Blue Star" link, the onMouseOver event-handler calls the MM_swapImage() function, and passes to it information which will cause the solid white square image to be replaced with the blue star image. When the mouse pointer is passed off of the "Blue Star" link, the onMouseOut event-handler calls the MM_swapImgRestore() function to restore the image of the solid white square.
When the page is fetched by the browser, a solid white image (starblnk.gif) is loaded by the HTML <img> (image) tag, and the image space is given the name starspace. When the browser has finished loading the Web page, the onLoad event-handler initiates repeated calls to the "MM_preloadImages" function which fetches each of the colored star image files. The images are saved within an array for systematic retrieval and display. Pre-loading the images enables a much more rapid exchange of images subsequently. The onMouseOver event-handler exchanges a colored star image for the solid white image within the named image starspace. The onMouseOut event-handler restores starspace to the original solid white image. The JavaScript event-handlers and functions were inserted automatically into the HTML file by Dreamweaver as the behaviors were assigned to the colored star links.
Download a self-extracting zip-file which contains the HTML portion of Example 3 with instructions for building this example with Dreamweaver. The zip-file contains the HTML file (example3b.htm) and the seven .gif image files (starblnk.gif, starblue.gif, stargold.gif, stargren.gif, starpurp.gif, starslvr.gif, staryell.gif).