I want to display div above image so that div’s top is aligned with cursor.
As cursor is moved, the div should be moved as well (right now just vertically).
In IE (pure javascript please).
<head runat="server">
<title></title>
<style type="text/css">
#ToolTip{position:absolute; width: 200px;background-color:Lime; top: 0px; left: 0px; z-index:400;visibility:hidden;}
</style>
<script language="javascript" type="text/javascript">
function On() {
MoveToolTip("ToolTip", "event.y", "event.x");
document.getElementById('ToolTip').style.visibility = 'visible';
}
function Off() {
MoveToolTip("ToolTip", 0, 0);
document.getElementById('ToolTip').style.visibility = 'hidden';
}
function MoveToolTip(layerName, top, left) {
document.getElementById(layerName).style.top = (eval(top));
//document.getElementById(layerName).style.left = (eval(left) - 360);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="ToolTip" >This is a test </div>
<a href="www.www.com"><img alt="mg" border="0" src="http://www.google.com/logos/holiday09_4.gif" onmouseout="Off();" onmouseover="On();" /></a>
</div>
</form>
</body>
</html>
Here’s a possible fix for your problem:
Things I changed:
OntoshowToolTipOfftohideToolTipeventvariable is now passed to theshowToolTipfunction. This is needed to get the cursor’s x, y positionreturn falsetoshowToolTipandhideToolTiponmouseoutandonmouseoverwith the more widely supportedonmousemoveeventonmousemoveevent to document, which callshideToolTiponmousemoveevent to the tool tip div, which callsshowToolTip+ "px"statement to the.style.topassignment. Some browsers get confuse if you assign an integer to a style.onmousemoveattributes from the markupcursor: pointerstyle to the tool tip. This removes cursor flicker.I’ve also posted a working example: http://www.the-xavi.com/static/so-hover-div.html
Hope this helps.