Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Map Mouse Over

Status
Not open for further replies.

kathyc2020

Programmer
Dec 17, 2003
8
CA
I have an image map with selected hot spots.

When the user moves their mouse over the selected area,
I would like a transparent image to hover just over
the mouse position and when mouse moves off the selected
area, image disappears.

I have found quite a lot of code for tooltips etc., but
nothing along the lines of what I need.

Does anyone have any suggestions?
 
Put your image into a <div> tag:
Code:
<div id=&quot;imageContainer&quot; 
     style=&quot;position:absolute; display:none;&quot;>
 <img src=&quot;transparent.gif&quot;>
</div>

Write your onmouseover handler to set the position of the div to near the mouse pointer and set the display property to block;
Code:
function handleMouseOver(){
 var invDiv = document.getElementById(&quot;imageContainer&quot;);
 var mouseX = parseInt(event.clientX);
 var mouseY = parseInt(event.clientY);

 // Set the position of the div about 10px up and back from
 // the mouse pointer
 var divPosX = mouseX - 10;
 var divPosY = mouseY - 10;

 invDiv.style.left = divPosX;
 invDiv.style.top = divPosY;
 invDiv.style.display = &quot;block&quot;;
}
The mouseout handler only needs to hide the div
Code:
function handleMouseOut(){
 var invDiv = document.getElementById(&quot;imageContainer&quot;);
 invDiv.style.display = &quot;none&quot;;
}


Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

AU.gif
Check out Tek-Tips Australia New Zealand forum1155
NZ.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top