Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: mouseout not triggering if mouse is moved out too fast?

Tags:

jquery

$(".np-button").mouseover(function() { 
    $(this).hide();
    $(this).next().show();
});
$(".login-button").mouseout(function() {
    $(this).hide();
    $(this).prev().show();
});

The first button hides itself and shows the second button in the same place. All good.

However, if I quickly mousover and mouseexit the first button, the second button will stay active (the mouseout event related to the second button won't be triggered).

How can I fix this?

Edit: here's the jsfiddle http://jsfiddle.net/aArub/ . Thanks in advance.

like image 513
Tool Avatar asked Mar 12 '12 19:03

Tool


People also ask

In what situation will the event Mouseleave will take effect trigger?

The mouse leave event will be triggered whenever the mouse cursor leaves from the selected element and after the occurrence of the event, it implements a mouse leave event that has been attached to an event handler function to run.

What is difference between Mouseenter () and mouseover () event?

The mouseover event triggers when the mouse pointer enters the div element, and its child elements. The mouseenter event is only triggered when the mouse pointer enters the div element.

Which event handler will be triggered by the mouse being moved off an element?

If you depress the mouse button on an element and move your mouse off the element, and then release the mouse button. The only mousedown event fires on the element. Likewise, if you depress the mouse button, and move the mouse over the element, and release the mouse button, the only mouseup event fires on the element.

What is Mouseleave in jQuery?

jQuery mouseleave() MethodThe mouseleave event occurs when the mouse pointer leaves the selected element. The mouseleave() method triggers the mouseleave event, or attaches a function to run when a mouseleave event occurs.


1 Answers

There is very simple way to do this without using javascript. Just CSS. Of course if you want just make element visible or not.

Example HTML:

<div class="visible">
    <div class="hidden">Some text</div>
</div>

CSS:

.hidden{
    display: none;
}
.visible:hover .hidden{
    display: block;
}

It helps to avoid situation, when mouseleave or mouseout are not triggered.

like image 90
instead Avatar answered Oct 04 '22 21:10

instead