J
Justin Rowe
I'm attempting to design a site with alot of dynamic content and
intractability, however I've hit a snag when it comes to the function of
the onMouseOver and onMouseOut events. Using a bit of code from
QuirksMode to grab the location of the mouse, I've built a tooltip
function to show a tooltip to the user depicting the target of a link,
the problem is when you mouse over the box that the tooltip function is
attatched to the tooltip flickers... Alot. I attempted to halt the
flickering and movement of the tooltip as the mouse moves across the
link (which is a 15x18 red square) but it seems that even as you move
about in the square, it keeps calling it's MouseOut event.
The following is the JavaScript code in question:
function inittooltip(target)
{
tltp = new getObj(target);
tltp.obj.onmouseover = showtooltip;
tltp.obj.onmouseout = stoptooltip;
}
function showtooltip(e)
{
var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)
var posx = 0;
var posy = 0;
var targ;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}else if (e.clientX || e.clientY)
{
posx = e.clientX;
posy = e.clientY;
if (isIE)
{
posx += document.body.scrollLeft;
posy += document.body.scrollTop;
}
}
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
if (targ == "[object HTMLImageElement]") targ = targ.parentNode;
tltarg = new getObj('tltp' + targ.id);
if (tltarg.style.display != "block")
{
tltarg.style.left = posx + 'px';
tltarg.style.top = (posy - 20) + 'px';
tltarg.style.display = "block";
}
}
function stoptooltip(e)
{
var targ;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode;
if (targ == "[object HTMLImageElement]") targ = targ.parentNode;
tltarg = new getObj('tltp' + targ.id);
tltarg.style.display = "none";
}
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = getObjNN4(document,name);
this.style = this.obj;
}
}
function getObjNN4(obj,name)
{
var x = obj.layers;
var thereturn;
for (var i=0;i<x.length;i++)
{
if (x.id == name)
thereturn = x;
else if (x.layers.length)
var tmp = getObjNN4(x,name);
if (tmp) thereturn = tmp;
}
return thereturn;
}
As you can see, I have the code checking to see if the element is
already being displayed (display != "block"), but when I put an alert
box in to show me what the display value for the element is, I
consistantly get "none".
If anyone knows a way to solve this, or at the least why it is firing
the MouseOut event willy nilly, I would be much obliged.
intractability, however I've hit a snag when it comes to the function of
the onMouseOver and onMouseOut events. Using a bit of code from
QuirksMode to grab the location of the mouse, I've built a tooltip
function to show a tooltip to the user depicting the target of a link,
the problem is when you mouse over the box that the tooltip function is
attatched to the tooltip flickers... Alot. I attempted to halt the
flickering and movement of the tooltip as the mouse moves across the
link (which is a 15x18 red square) but it seems that even as you move
about in the square, it keeps calling it's MouseOut event.
The following is the JavaScript code in question:
function inittooltip(target)
{
tltp = new getObj(target);
tltp.obj.onmouseover = showtooltip;
tltp.obj.onmouseout = stoptooltip;
}
function showtooltip(e)
{
var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)
var posx = 0;
var posy = 0;
var targ;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}else if (e.clientX || e.clientY)
{
posx = e.clientX;
posy = e.clientY;
if (isIE)
{
posx += document.body.scrollLeft;
posy += document.body.scrollTop;
}
}
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
if (targ == "[object HTMLImageElement]") targ = targ.parentNode;
tltarg = new getObj('tltp' + targ.id);
if (tltarg.style.display != "block")
{
tltarg.style.left = posx + 'px';
tltarg.style.top = (posy - 20) + 'px';
tltarg.style.display = "block";
}
}
function stoptooltip(e)
{
var targ;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) targ = targ.parentNode;
if (targ == "[object HTMLImageElement]") targ = targ.parentNode;
tltarg = new getObj('tltp' + targ.id);
tltarg.style.display = "none";
}
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = getObjNN4(document,name);
this.style = this.obj;
}
}
function getObjNN4(obj,name)
{
var x = obj.layers;
var thereturn;
for (var i=0;i<x.length;i++)
{
if (x.id == name)
thereturn = x;
else if (x.layers.length)
var tmp = getObjNN4(x,name);
if (tmp) thereturn = tmp;
}
return thereturn;
}
As you can see, I have the code checking to see if the element is
already being displayed (display != "block"), but when I put an alert
box in to show me what the display value for the element is, I
consistantly get "none".
If anyone knows a way to solve this, or at the least why it is firing
the MouseOut event willy nilly, I would be much obliged.