Position a popup on mouseover - coordinates seem incorrect?

Hi All,
I'm trying to popup a div (containing an image) over another image (a chart). I do this by creating an image map (made up of area tags) and assigning a javascript function to the mouseover and mouseout events.
I then collect the coordinates (using window.event.clientX/Y) and try to popup the div. However, i'm struggling with the Y coordinate - it seems to move the opposite way to the mouse.
Does anyone have any ideas?
Thanks,
S Armondi
Javascript:
function ShowTradeCallout()
{
   var div = document.getElementById('ctl00_ContentPlaceHolder1_test');
   var img = document.getElementById('ctl00_ContentPlaceHolder1_chart');
   if (true) //if (!PopupDisplayed)
   {
       var x = 0,y = 0;
       x = event.clientX;
       y = event.clientY;
       if (document.pageYOffset)
       {
           x += document.pageXOffset;
           y += document.pageYOffset;
       }
       else if(document.documentElement && document.documentElement.scrollTop)
       {
           x += document.documentElement.scrollLeft;
           y += document.documentElement.scrollTop;
       }
       else if(document.body)
       {
           x += document.body.scrollLeft;
           y += document.body.scrollTop;
       }
       div.setAttribute("class", "displayedCallout");
       div.setAttribute("className", "displayedCallout");
       div.style.pixelLeft = x;
       div.style.pixelBottom = y;
   }
}
function HideTradeCallout()
{
    var div = document.getElementById("ctl00_ContentPlaceHolder1_test");
    div.setAttribute("class", "hiddenCallout");
    div.setAttribute("className", "hiddenCallout");
}

Open in new window

popup1.png
popup2.png
popup3.png
LVL 1
peddleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TNameCommented:
Hi, why do you use "pixelBottom" instead of "pixelTop"? That should be the reason for the problem you've described...

But why not make it Firefox-compatible also? Here's an example (moved the div movement into the body's onMousemove, so that it will keep upddating)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript">
 
 
function MoveTradeCallout(e)
{
   var div = document.getElementById('ctl00_ContentPlaceHolder1_test');
   var img = document.getElementById('ctl00_ContentPlaceHolder1_chart');
   if (true)  
   {   
       var e=e||window.event;
       var x = 0,y = 0;
       x = e.clientX;
       y = e.clientY;
       if (document.pageYOffset)
       {
           x += document.pageXOffset;
           y += document.pageYOffset;
       }
       else if(document.documentElement && document.documentElement.scrollTop)
       {
           x += document.documentElement.scrollLeft;
           y += document.documentElement.scrollTop;
       }
       else if(document.body)
       {
           x += document.body.scrollLeft;
           y += document.body.scrollTop;
       }	   
	   div.style.left = x+1+'px';
       div.style.top= y+1+'px';	   
   }
}
 
 
function ShowTradeCallout()
{
   var div = document.getElementById('ctl00_ContentPlaceHolder1_test');
   var img = document.getElementById('ctl00_ContentPlaceHolder1_chart');
   if (true) //if (!PopupDisplayed)
   {   
	   div.setAttribute("class", "displayedCallout");
       div.setAttribute("className", "displayedCallout");  	  
   }
}
 
function HideTradeCallout()
{
    var div = document.getElementById("ctl00_ContentPlaceHolder1_test");
    div.setAttribute("class", "hiddenCallout");
    div.setAttribute("className", "hiddenCallout");
}
 
</script>
<style>
#ctl00_ContentPlaceHolder1_chart { 
	margin-top:400px;
	margin-left:300px;
	border:1px solid #ccc;	
 }
#ctl00_ContentPlaceHolder1_test { 
	height:100px;
	width:200px;
	background-color:#ddd;
	border:2px solid #f00;
	position:absolute;
	opacity:.70; filter:alpha(opacity=70); -moz-opacity:0.7;
 }
 .displayedCallout { 
	display:block;
 }
 .hiddenCallout { 
	display:none;
 } 
 
</style>
</head>
<body onMousemove="MoveTradeCallout(event)">
<img src="http://www.google.com/intl/en_ALL/images/logo.gif" id="ctl00_ContentPlaceHolder1_chart" onMouseover="ShowTradeCallout()" onMouseout="HideTradeCallout()" />
<div id="ctl00_ContentPlaceHolder1_test" class="hiddenCallout"></div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peddleAuthor Commented:
Thank you very much - excellent answer!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.