Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouseover and Mouseout function jQuery

I have this script:

$("#teaser ul.buttons li").mouseover(function()
    {
        $("a",this).animate({ left: '0' },350);
    }).mouseout(function()
    {

        $("a",this).animate({ left: '-11px' },350);
    });

But when i now hover over the a element. The mouseover and mouseout going continu. How can i change this script. That when i hover of the a element. That the mouseout launch when i hover off the element.

like image 265
Mike Avatar asked Mar 02 '11 11:03

Mike


People also ask

What is Mouseout in jQuery?

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

What is jQuery mouseover?

The 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.

What is the difference between Mouseout and Mouseleave?

This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element).

What is Mouseout?

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.


2 Answers

use mouseenter and mouseleave instead of mouseover and mouseout

like image 179
Rafay Avatar answered Oct 04 '22 14:10

Rafay


Is http://jsfiddle.net/BBUJ7/ what you are looking for? I changed the mouseover and mouseout to hover since you mentioned hovering in the question and added a {position:relative} CSS rule.

like image 43
andyb Avatar answered Oct 04 '22 12:10

andyb