► This is a bit less fidgety, but it can't detect moving from a parent element to one of its children without first moving the mouse completely off said parent.
var $div = $('<div id="highlighter">').css({
'background-color': 'rgba(255,0,0,.5)',
'position': 'absolute',
'z-index': '65535'
}).hide().prependTo('body');
var $highlit;
$('*').live('mousemove', function(event) {
if (this.nodeName === 'HTML' || this.nodeName === 'BODY')
{
$div.hide();
return false;
}
var $this = this.id === 'highligher' ? $highlit : $(this),
x = event.pageX,
y = event.pageY,
width = $this.width(),
height = $this.height(),
offset = $this.offset(),
minX = offset.left,
minY = offset.top,
maxX = minX + width,
maxY = minY + height;
if (this.id === 'highlighter')
{
if (minX <= x && x <= maxX
&& minY <= y && y <= maxY)
{
// nada
}
else
{
$div.hide();
}
}
else
{
$highlit = $this;
$div.offset(offset).width($this.width()).height($this.height()).show();
}
return false;
});
Hopefully that helps get the ball rolling. You could probably tweak what I've written to use document.elementFromPoint(x, y) to check whether or not the mouse has moved into a child element of the element currently highlighted. I'm not awake enough to figure this out right now.
Alternately, if outlining is as good as highlighting to you, you could try the approach I mentioned in my comment to your original question. Draw 4 divs around the currently hovered element* - that's one div for each edge of the outline box. No more drawing elements between you and your actual content!
*I'd bet that document.elementFromPoint(x, y)
will make getting the element under your mouse much easier here.