Frankie
Frankie

Reputation: 2265

What event should I use to hide context menu in jquery?

I have a contextmenu that shows on certain elements when you right click. This works no problem.

wrapper.on('contextmenu', 'div.outer', function (e) {        
    context_menu.css({
        left: e.pageX,
        top: e.pageY,
        zIndex: '101'
     }).fadeIn();
     return false;
});

//This does not work correctly
context_menu.mouseout(function (e) {
    $(this).fadeOut();
});

I'm trying to figure out how to hide the menu when the user is not hovered over the menu. Right now as soon as I move the mouse after I right click it fades out.

Upvotes: 1

Views: 900

Answers (3)

Ram
Ram

Reputation: 144689

$(selector).hover(handlerIn, handlerOut);

is shorthand for:

$(selector).mouseenter(handlerIn).mouseleave(handlerOut);

Upvotes: 0

Starx
Starx

Reputation: 78991

The events, should most probably be mouseleave since its a container.

context_menu.mouseleave(function (e) {
    $(this).fadeOut();
});

Upvotes: 1

Daniel Hallqvist
Daniel Hallqvist

Reputation: 822

Look here: http://api.jquery.com/hover/

the hover() event has one method for when the mouse is over the element and one for when it's not.

Upvotes: 0

Related Questions