Since the JQuery Forward Mouse Event Example link is currently dead, I wrote some jQuery code to handle a simple case:
- overlay div with a transparent image and no links
- underlay div with links
Goal: keep overlay visible, make links work and cursor change when over a link.
Method: compare the mouse location to each link offset().
I don't handle general mouse events, I just treat the events I need ad-hoc. So it's really a workaround instead of the best solution, which would handle every mouse event abstractly, something like using Wildcard's above quickDelegate() after checking the geometry. Also I only care about certain link elements, not the whole layered DOM.
function mouse_event_over_element(evt, elem) {
var o= elem.offset();
var w= elem.width();
var h= elem.height();
return evt.pageX >= o.left && evt.pageX <= o.left + w && evt.pageY >= o.top && evt.pageY <= o.top + h;
}
$(overlay_selector).click(function(e){
$(underlay_selector + ' a').each(function() {
if (mouse_event_over_element(e, $(this))) {
// $(this).click(); // trigger a jQuery click() handler
// quickDelegate(e, this); // not in IE8
// this.click(); // maybe not in Mozilla pre-HTML5
window.location.href= this.href;
return false;
}
});
});
$(overlay_selector).mousemove(function(e){
var newcursor= 'default';
$(underlay_selector + ' a').each(function() {
if (mouse_event_over_element(e, $(this))) {
newcursor= 'pointer';
// $(this).mouseenter(); // trigger a one-argument jQuery hover() event (no mouseleave)
return false;
}
});
$(overlay_selector).css('cursor', newcursor);
});
Using the geometry function 'mouse_event_over_element()' you can handle other events and elements.
To do: figure out what mouse events trigger the tooltip over <a title="foo">
, and trigger() them, or replicate showing the tooltip. Same for the status line.
..............................
Edit 2014/09
..............................
User user2273627 sggested:
For the default tooltip and status-line you can use the z-index
css-property. Check if the mouse is over a link and set the z-index
for that link. $(this).css('z-index','9'); Put an else when the mouse
is not over an element and set the z-index to auto. Make sure you set
the underlying links position: relative in the css-file, otherwise
z-index will not work.