Discussion Locked

JavaScript

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am working on an interface for my web page..
I need to write a JavaScript that will cause a seperate image to change when I move my mouse over a button image.. I need to define two hotspots on the button image (like an image map in html). The interface is designed such that there are three images side by side. The two outside images are for four buttons. The center image will change when the mouse moves over one of the buttons.. I would also like the button to change at the same time..I haveinvested a lot of time in the graphics and now I would love to see it work..
Thanks,
Dwayne

3 replies

by twistypigeon

If the image is truly separate, then you should be able to do an image swap using the .src property of the named image. This will probably only work in IE, but you should be able to investigate adjusted methods that work with Netscape aswell.
If you have an tage with the ID property set to something, eg , then you can reference that object in Javascript using MyPic. The URL of the image is in the src property, so the source img for MyPic is MyPic.src. All you have to do is in the onmouseover event of the other image, set the src of the main one.
eg
you will have to do an onmouseout event to set the image back again.
Defining a hot spot would be a little more tricky, but if you use the window.event.x & window.event.y properties with the onmousemove event, you can pick up the exact X & Y coords of the mouse pointer. This would allow you to define some bounds for an area on an object.

Hope thishelps!

This discussion is closed to new replies.