Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop jQuery Mouseleave Event When Entering Another Specific Element

I need to know how I can stop my mouseleave event from occuring when I slide my mouse over to a different element (link). How can I setup a condition that says to only do the mouseleave animation if I have not entered a specific element?

$(activity_link).mouseenter(function() {
    $(this).siblings(".delete_place").animate({ 
                                               "left" : "-28px"
                                              }, 300);     
}).mouseleave(function() {
     $(this).siblings(".delete_place").animate({
                                                "left" : 0
                                               }, 300);
});
like image 554
Jason Biondo Avatar asked Oct 21 '22 11:10

Jason Biondo


1 Answers

Use of event relatedTarget:

$(activity_link).mouseenter(function () {
    $(this).siblings(".delete_place").animate({
        "left": "-28px"
    }, 300);
}).mouseleave(function (e) {
    if (e.relatedTarget != myElem) { //where myElem is a HTML element
        $(this).siblings(".delete_place").animate({
            "left": 0
        }, 300);
    }
});
like image 161
A. Wolff Avatar answered Nov 03 '22 23:11

A. Wolff