jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
hover(over, out)
hover(over,out)

一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法。

这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态。 当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数。当鼠标移出这个元素时,会触发指定的第二个函数。

而且,会伴随着对鼠标是否仍然处在特定元素中的检测(例如,处在div中的图像),如果是,则会继续保持“悬停”状态,而不触发移出事件(修正了使用mouseout事件的一个常见错误)。

返回值:jQuery

参数:

  • over (Function): 鼠标移到元素上要触发的函数
  • out (Function): 鼠标移出元素要触发的函数

示例:

$("p").hover(function(){
  $(this).addClass("over");
},
function(){
 $(this).addClass("out"); 
}); 
 
?hover(over, out)

A method for simulating hovering (moving the mouse on, and off, an object). This is a custom method which provides an 'in' to a frequent task.

Whenever the mouse cursor is moved over a matched element, the first specified function is fired. Whenever the mouse moves off of the element, the second specified function fires. Additionally, checks are in place to see if the mouse is still within the specified element itself (for example, an image inside of a div), and if it is, it will continue to 'hover', and not move out (a common error in using a mouseout event handler).

Return value: jQuery
Parameters:

  • over (Function): The function to fire whenever the mouse is moved over a matched element.
  • out (Function): The function to fire whenever the mouse is moved off of a matched element.

Example:

 $("p").hover(function(){
     $(this).addClass("hover");   
 },function(){
     $(this).removeClass("hover");  
 });