Hover + Mousemove, how could I reduce the repeated code?
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*}
);
精彩评论