jquery将鼠标hover在外面

我希望鼠标hover在链接上的简单向下滑动动画。 我可以让鼠标上class,但我无法弄清楚如何让mouseout做到这一点。

这是我对hover效果的看法:

  google.load("jquery", "1.3.2"); //load version 1.3.2 of jQuery google.setOnLoadCallback(function() { jQuery( function($) { $("a.button").hover(function(){$(this).animate({"marginTop": "0px"}, "fast") }); }); });  

当鼠标移出时,如何让这个边距上移16px?

jQuery中的hover事件需要2个回调函数:一个指针在项目上移动时,一个在它离开时:

 $(item).hover(function() { ... }, function() { ... }); 

在你的情况下:

 $("a.button").hover( function() { $(this).animate({"marginTop": "0px"}, "fast"); }, function() { $(this).animate({"marginTop": "16px"}, "fast"); } ); 

在较新版本的jQuery(> = 1.7)中,您也可以采用以下方法:

 $("a.button").on('mouseenter',function(){ $(this).animate({"marginTop": "0px"}, "fast"); }); $("a.button").on('mouseleave',function(){ $(this).animate({"marginTop": "16px"}, "fast"); }); 

在我看来,这是一个更简洁的方法,它也利用了新的.on()函数( 这里的文档 )

更简单的解决方案

 $("a.button").hover(function() { $("a.button").css("cursor","pointer"); });