Now the button has a name that can be used as a reference when we want javascript to replace it with another image.
We need to tell the browser that once a
mouse is rolled over the image, the browser should execute a function
that replaces the image.
This is done with the
onMouseOver event.
In addition we also need to tell the
browser that once the user rolls the mouse away from the image, another
javascript should be solved in order to let the initial image of the
button return.
This is done with the
onMouseOut event.
The final HTML code looks like this:
>
This is all you need to do in the HTML part of the page. The rest is done in javascript.
Note:
The mouse events are added to the
tag - NOT the image tag. This is because browsers do not look for
mouseover events on images. As stupid as it may sound it is nevertheless
true. Therefore we can only make images animated by turning them into
links. Since browsers understand mouseover events on links, they will
register a mouse event on an image, if that image is a link.
THE JAVASCRIPT CODE
The following javascript should be added to the head part of your webpage.
If you want more than one button on your
page, all you need to do is double each line referring to button1 and
change it to button2, button3 or whatever number of buttons you might
have.
|
|
| |
"Better Than Books - As Easy As It Gets!"
|
|
|
No comments:
Post a Comment