0

我查看了stackoverflow,我不是程序员,我确定我缺少一些基本知识,并且jquery参考网站没有帮助。

我必须同时使用 mouseove 和 hover 来检测鼠标是否在图像上方移动(可能有动画)。我的问题是我想减少我用来做mystuff的相同代码,但同时我需要当鼠标离开时做myotherstuff的替代方案。

我应该如何编写代码?

$("#central .img").mousemove(
   function(){*mystuff*}
);

$("#central .img").hover(
   function(){*mystuff*}
   ,function(){*myotherstuff*}
);

感谢您的帮助

4

1 回答 1

0

您可以命名您的函数并重用它。

function myfunction(){*mystuff*}
$("#central .img").mousemove(myfunction);

$("#central .img").hover(
   myfunction
   ,function(){*myotherstuff*}
);
于 2011-03-27T11:53:21.767 回答