Search code examples
jqueryclickhidejquery-animatemouseout

jquery: mouseout event firing even after I used a click event to hide the div


jQuery("#na").mouseover(function()
{
    jQuery("#na").animate({width:"325px", height:"203px", left:"-40px", top:"-25px"}, 200)
});

jQuery("#na").mouseout(function()
{
    jQuery("#na").stop()
    jQuery("#na").animate({width:"244px",height:"152px", left:0, top:0}, 200)
});

jQuery("#na").click(function()
{
    jQuery("#na").hide()
    jQuery("#back").show()
});

so thats my code, the problem is when the click event is triggered all is fine, na dissapears but the moment you move your mouse it reappers again. I figured the problem is that the mouseout event is being triggered, but for the life of me cant figure out how to fix it. any ideas?


Solution

  • Inside the mouseout method, check if the "na" is visible or hidden. If it is hidden, dont do anything, else you can do the animate.

    EDIT:

    Try your mouseout method like this:

    jQuery("#na").mouseout(function(){
        if(jQuery("#na").is(":visible")){
           jQuery("#na").stop()
           jQuery("#na").animate({width:"244px",height:"152px", left:0, top:0}, 200)
        }
    });