Saturday, December 15, 2007

Mouse over popUp that is working fine in Mozilla but not working in IE.

Mouse over popUp that is working fine in Mozilla but not working in IE.
In IE its position is not coming proper unable to shift it.
Code:

var offX= -180; // how far from mouse to show tip
var offY= 12;

var mouseX, mouseY;
function trackMouse(evt) {
standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
if (tipOn) positionTip(evt);
}

function positionTip(evt) {
if (!tipFollowMouse) {
mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
}
// tooltip width and height
var tpWd = (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
var tpHt = (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
// document area in view (subtract scrollbar width for ns)
var winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
var winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
// check mouse position against tip and window dimensions
// and position the tooltip
if ((mouseX+offX+tpWd)>winWd)
tipcss.left = mouseX-(tpWd+offX)+"px";
else tipcss.left = mouseX+offX+"px";
if ((mouseY+offY+tpHt)>winHt)
tipcss.top = winHt-(tpHt+offY)+"px";
else tipcss.top = mouseY+offY+"px";
if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

In popUp there is an init method which is loaded on body using tag.

Solution:

This is an area where there is much incompatibility.

The values pageX and pageY are part of the Mozilla set of properties, not the W3C standard DOM properties. IE doesn't know them.
The W3C standard DOM reports the mouse locations with clientX and clientY. The problem is that these do not take document scrolling into account, but just use the browser window location.

Reference:http://www.daniweb.com/forums/thread93585.html

No comments: