Some sites have images on their pages that change when you move the mouse pointer over it. How do you create such an effect? First a warning, this technique only works in Netscape Navigator 3.0 and up. Internet Explorer doesn't support it in 3.0, but 4.0 does.
Changing an image only works if the image is inside a link, (the A element). Normally when you use an image in a link the source looks something like this:
![]() |
<A href="index.html"> |
![]() |
![]() |
To identify which of the images on a page must change you must give the image a name, so it can be referred to later on:
![]() |
<A href="index.html"> |
![]() |
![]() |
Now add the JavaScript that actually changes the images when needed. In the HEAD of the page put this script:
![]() |
<SCRIPT language="javascript1.1"> |
Then add an onMouseOver event handler to the link. This is a JavaScript statement that gets executed when the user moves the mouse over it:
![]() |
<A href="index.html" onMouseOver="changeImg('imgHome',gifHome2)"> |
![]() |
![]() |
This works ok, but now the image doesn't change back when the mouse pointer is no longer over the image. To correct this you also have to add an onmouseout event handler to the link:
![]() |
<A href="index.html" onMouseOver="changeImg('imgHome',gifHome2)" |
![]() |
![]() |
Follow these steps:
objectName
and
image.gif
to the ones you need.
objectName = new Image(width,height)
objectName.src = "image.gif"
The first line creates a new image object, the second loads the image in memory.
Function: | changeImg(<image-name>,<object-name>) |
Parameters: |
|