|
Creating special
effects with JavaScript
Special
effects are triggered by events that are most often directed by the user.
Such an event can be the loading of a WWW-page, which causes an animation
to start, a sound to be heard or page statistics to be updated. Another
event is called 'mouse-over', which starts animations or sounds when the
mousepointer is moved over an object on the WWW-page.
The
mouse-over event is a useful trigger to attract extra attention to specific
objects. For example, the logo of 'Lovely Maps' can be replaced by another
image when the mousepointer is upon the image area and restored when the
mouse is outside the image area.
In
a browser this looks like (move your mousepointer over the image to see
the effect):
The
JavaScript code for this special effect is:
<
a href="#"
onMouseOver="MM_swapImage('document.logo','document.logo',
'images/lovelymaps2.gif','MM_swapImage1')"
onMouseOut="MM_swapImgRestore()"
>
<
img src="images/lovelymaps.gif" width="100" height="100"
name="logo"
border="0" > </a >
The
functions "MM_swapImage" and "MM_swapImgRestore" are
defined in the header section of the HTML-code:
<head>
<script
language = "JavaScript">
function
MM_swapImage() {.....}
function
MM_swapImgRestore() {.....}
</script>
</head>
|
|