悬停+ mousemove,如何减少重复代码?
我查看了 stackoverflow,我不是程序员,我确信我缺少一些基本知识,并且 jquery 参考网站它没有帮助。
我必须同时使用鼠标移动和悬停来检测鼠标是否在图像顶部移动(可能有动画)。我的问题是,我想减少用于执行 mystuff 的相同代码,但同时我需要当鼠标离开执行 myotherstuff 时的替代方案>。
代码应该怎么写呢?
$("#central .img").mousemove(
function(){*mystuff*}
);
$("#central .img").hover(
function(){*mystuff*}
,function(){*myotherstuff*}
);
感谢您的帮助
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 detect 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以命名您的函数并重用它。
You can name your function and reuse it.