Is there a quick & easy way to do this in jQuery that I'm missing?
I don't want to use the mouseover event because I'm already using it for something else. I just need to know if the mouse is over an element at a given moment.
I'd like to do something like this, if only there was an "IsMouseOver" function:
function hideTip(oi) {
setTimeout(function() { if (!IsMouseOver(oi)) $(oi).fadeOut(); }, 100);
}
I took SLaks' idea and wrapped it in a small class.
Extending on what 'Happytime harry' said, be sure to use the .data() jquery function to store the timeout id. This is so that you can retrieve the timeout id very easily when the 'mouseenter' is triggered on that same element later, allowing you to eliminate the trigger for your tooltip to disappear.
This would be the easiest way of doing it!
You can use jQuery's mouseenter and mouseleave events. You can set a flag when the mouse enters the desired area and unset the flag when it leaves the area.
Here is a function which helps you check if the mouse is inside an element or not. The only thing you should do is to call the function where you can have a live mouse-associated EventObject. something like this:
You can see the source code here in github or at the bottom of the post:
https://github.com/mostafatalebi/ElementsLocator/blob/master/elements_locator.jquery.js
Set a timeout on the mouseout to fadeout and store the return value to data in the object. Then onmouseover, cancel the timeout if there is a value in the data.
Remove the data on callback of the fadeout.
It is actually less expensive to use mouseenter/mouseleave because they do not fire for the menu when children mouseover/mouseout fire.