i have the following script firing mouseover and mouseout always twice! what do you suggest i do wrong (unbind, return e.g.)? i tried a few things but nothing helped.
here is the code:
$('#container').delegate('div.showmenu', 'mouseover mouseenter mouseout mouseleave', function(e){
if (e.type === 'mouseover' || e.type==='mouseenter') { //jIE requires mouseenter, does not fire mouseover
if($(this).parents().closest('div').hasClass('whatever')){
alert(e.type); //double-alerts mouseover
menu.show();
foldercmenu.hover(
function(){
$(this).show();
},
function(){
$(this).hide();
}
);
}else {
//do other stuff :-)
}
}else if(e.type==='mouseout' || e.type==='mouseleave'){ //IE requires mouseleave, does not fire mouseout
alert(e.type); //double-alerts mouseout
menu.hide();
$(this).unbind('mouseover mouseenter mouseout mouseleave');
}
//return false;
});
The mouseover event occurs when a mouse pointer comes over an element, and mouseout – when it leaves. These events are special, because they have property relatedTarget . This property complements target . When a mouse leaves one element for another, one of them becomes target , and the other one – relatedTarget .
The mouseout event is fired at an Element when a pointing device (usually a mouse) is used to move the cursor so that it is no longer contained within the element or one of its children.
The mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.
jQuery mouseover() MethodThe mouseover event occurs when the mouse pointer is over the selected element. The mouseover() method triggers the mouseover event, or attaches a function to run when a mouseover event occurs.
mouseover
and mouseout
a triggered when you enter/leave a child of the element, maybe that's the effect you are seeing.
An other problem is that you are binding the handler to both, mouseover
and mouseenter
( and mouseleave
and mouseout
).
Only bind to mouseenter
and mouseleave
. jQuery is already taking care of the browser differences.
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