2012-04-06 26 views
1

我有一個contextmenu,在右鍵單擊時顯示某些元素。這工作沒有問題。我應該使用什麼事件來隱藏jQuery中的上下文菜單?

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(); 
}); 

我想弄清楚如何隱藏菜單,當用戶沒有在菜單上盤旋。現在,當我點擊鼠標右鍵後,鼠標移動就會消失。

回答

1

事件,最有可能是mouseleave,因爲它是一個容器。

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

看看這裏:http://api.jquery.com/hover/

懸停()事件有當鼠標移動到元素的一個方法,一個用於當它不是。

+0

鼠標離開工作。謝謝。 – Frankie 2012-04-06 23:43:23

0

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

是簡寫:

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