开发者

Hover + Mousemove, how could I reduce the repeated code?

开发者 https://www.devze.com 2023-02-19 20:58 出处:网络
I looked at stackoverflow, and I am not a programmer, I am sure that I am missing some basic knowledge, and jquery reference website it isn\'t helping.

I looked at stackoverflow, and I am not a programmer, I am sure that I am missing some basic knowledge, and jquery reference website it isn't helping.

I have to use both mouseove and hover, to det开发者_JAVA百科ect if a mouse it is moving on top of an image (that could have an animation). My problem is that I want to reduce the same code that I use for doing the mystuff, but at the same time I need the alternative for when the mouse leaves to do the myotherstuff.

How should I write the code?

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

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

Thank you for your help


You can name your function and reuse it.

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

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

精彩评论

暂无评论...
验证码 换一张
取 消