I have a image in the shape of a Circle.
The circle is broken into 3 equal parts.
I have an image with the entire circle.
I have 3 other images, each only a piece of the circle but in the color green.
I have to do the following:
-
Display the original circle image.
-
Have a 3 buttons on the screen, each button is linked to the 3 parts of the circle. When clicked, it overlays the green image over the circle. So if you clicked all 3 buttons, the entire circle would be green. If you only clicked the 1st button, only that section of the circle would be green.
How can I implement this? Is it possible to overlay 2 images at once? Do I have to play with x and y positioning here? (the green image sections currently, if you place them over the original image, will lineup exactly with the original circle image.
Here’s a solution shown in straight JavaScript and also jQuery.
The straight JavaScript uses the DOM0 onclick handlers of the buttons which is OK because they’re only triggering one event. The onload handler for the window is more of a problem: you can only have one per document.
The jQuery solution is much shorter as you can see, but you’ll have to include the jQuery library. The
$( function(){} )takes the place of the window onload handler but you can have as many as you like.The images sector1.gif, sector2.gif and sector3.gif are transparent apart from the bits of the circle that are visible for them. You could use .png too but that wouldn’t work in ie6 without some tweakery.
_
_