I have a menu-like drop down container that hides via binding the "mouseleave" event.
<div id="container">
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
The problem I am having is when my container's child elements contain a SELECT object where the OPTIONS of the SELECT physically extend outside the bounds of the container. Consequently, hovering over the OPTIONS outside of the bounds trigger the "mouseleave" event to fire and close my drop down. The SELECT is a child of the container, so in this case I would expect the mouseleave event to recognize this.
An update on Blocka's solution as it doesn't work with Firefox correctly:
if ((typeof e.fromElement != 'undefined' && !e.fromElement.length) ||
(typeof e.fromElement == 'undefined' && e.target.tagName != 'SELECT')) {
// perform your mouseleave logic
}
A very simple and effective solution to this is to control the mouse pointer coordinates before performing the action. If the container out of focus to focus on the element "select", it checks the pointer. If the pointer is inside the container, it does not perform any action, however if this is the container element action is performed
$('#div_solapa_lateral').bind("mouseenter",function(){
$(this).animate({left:'0'},500);
});
$('#div_solapa_lateral').bind("mouseleave",function(e){
if ( e.clientX>360 || e.clientY<60 || e.pageY>625 )
$(this).animate({left:'-320'},500);
});
clientX and clientY to "position:relative;
"
pageX and pageY to "position:absolute;
"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With