Link to home
Start Free TrialLog in
Avatar of bangers3474
bangers3474

asked on

Floating Layer At Cursor Position, Fine in FF all over the place in IE, how to solve the IE problem?

Pushed a bit for time on this project and beginning to pull hair out!
I have a script that show a hidden div layer on rollover and hides on rollout. the div layer displays according to the cursor position.
I want the layer to appear on rollover of a section of an image (which happens).
The script allows the position of the div layer to be offset from the cursor position by changing x and y variables. All good.
However whilst it is consistent in FireFox it's all over the place in IE according to how far the page has been scrolled down. For example if the page is right at the top,  on rollover my div layer appear cut off at the bottom of the screen with the div layer roughly to the side and middle of the cursor position. If you then scroll down the page to avoid the div layer cutting off then rollover again the div layer appear cut off at the top of the screen and above the cursor position (as opposed to middled).
I think the script would be great if I could get at least some consistency when opening in IE, any thoughts?

An example of what I am testing can be found here: http://www.quinndirectbritishmasters.com/ism/sites/masters/2007/course3.php
Just rollover hole 1 on the course to see what I mean.

My script was from here:
http://www.willmaster.com/blog/css/Floating_Layer_At_Cursor_Position.html

CSS relating to the hidden div is:
div#uniquename3{
      color: #000000;
      display:none;
      position:absolute;
      border-style: solid;
      background-color: white;
      padding: 5px;
      height:400px;
      width: 247px;
}

the div layer looks like this:
<div id="uniquename3"
   ><img src="images/hole1.jpg" />
</div>

the rollover effect on a image map looks like this:
  <area shape="poly" coords="529,192,450,275,371,315,307,329,296,316,336,288,389,256,457,219,518,181" onmouseover="ShowContent('uniquename3'); return true;" onmouseout="HideContent('uniquename3'); return true;" href="javascript:ShowContent('uniquename3')" alt="the 1st"  />
(only important bit the href and onmouse effects.)

The javascript is as follows:
var cX = 0; var cY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
d.style.left = (cX+5) + "px";
d.style.top = (cY-150) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}

I've been changing the d.style.left = (cX+5) + "px";
d.style.top = (cY-150) + "px"; to offset the alignment.

Any though on how to get consistency in ie even if it is different to Firefox so that I at least come up with a consistent compromise.
Regards
bangers
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bangers3474
bangers3474

ASKER

Not really what I'm looking for. I don't really want to parse everything through javascript like this. I really would like what I have got lat the moment looked at and to see if it can be ammended can anyone help?
Sorry, I do not understand what you mean by "I don't really want to parse everything through javascript like this"
the library I suggest does what your code does, it just does it better and crossbrowser.
Basically what walter's code does and what you need to do in yours is to handle document.body.scrollTop
(or document.documentElement.scrollTop if you use a doctype that needs it)

Okay I'll have a go, I guess ii'm relucant because I have to parse everything through astring and make sure I replace markup like " \' which has the possibilty of being missed somewhere and ballsing up. Also If I could use div content I can see my work + if I want to show hide more complicated layouts divs are fine but the method you sent would be v.complicated for me anyway
>>I have to parse everything through astring and make sure I replace markup like " \'

What can this have to do with positioning an element?
Only single quotes have to be escaped

toolTips= new Array()
tooTips[0]='<img src="images/hole1.jpg" />';
tooTips[1]='<img src="images/hole2.jpg" />';

  <area shape="poly" coords="529,192,450,275,371,315,307,329,296,316,336,288,389,256,457,219,518,181"
onMouseOver="return escape(toolTips[0])"....

alternatively use

onMouseOver="return escape(document.getElementById('uniquename3').innerHTML)"....

Michel

Badotz: If he is to use the walterzorn, the example markup is in the mouseover event string like this


  <area shape="poly" coords="529,192,450,275,371,315,307,329,296,316,336,288,389,256,457,219,518,181"
onMouseOver="return escape('<img src=\'ThisImageIsEscaped.gif\'> and so on')"....
ah, right. Still, gotta love ol' WZ, eh?
Okay, tried it and it is great fro what I need it to do, here's the evidence,
http://www.quinndirectbritishmasters.com/ism/sites/masters/2007/course5.php
Thnaks again for sticking with me,
regards
bangers