在JQuery中,将鼠标悬停在鼠标悬停上有什么优势? [英] Any advantages of hover over mouseover in JQuery?

查看:81
本文介绍了在JQuery中,将鼠标悬停在鼠标悬停上有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JQuery API相当陌生. 我一直在使用鼠标悬停,但之前从未使用过悬停. 所以我想知道是否应该使用悬停.

I am fairly new to JQuery API. I have been using mouseover, but I have never used hover before. SO I am wondering if I should use hover instead.

推荐答案

好吧, .hover() 为事件 mouseenter

Well, .hover() binds two handlers for the events mouseenter and mouseleave, so it is a more convenient way and also easier to understand the purpose.

mouseenter mouseover 的区别在于mouseenter 是如果光标悬停在/进入了处理程序绑定到的元素的子元素,则不会触发.
当光标进入元素时,它仅触发一次.即使光标位于子元素上,也会始终触发mouseover.

mouseenter differs from mouseover so far as mouseenter is not fired if the cursor is over/enters a child element of the element the handler is bound to.
It is only fired once, when the cursors enters the element. mouseover is always fired, even if the cursor is over a child element.

了解差异的最佳方法是查看 .

The best way to see the difference is to have a look at the example of mouseleave().

此外,mouseovermouseout是真正的JavaScript事件,而mouseentermouseleave是jQuery(afaik)提供的事件.

Furthermore, mouseover and mouseout are real JavaScript events whereas mouseenter and mouseleave are events provided by jQuery (afaik).

最后,这取决于您要实现的目标.没有对与错,所有这些方法都有其用途.除非您显示一些代码,否则没有什么可说的了.

In the end, it depends on what you want to achieve. There is no right or wrong and all these methods have their purpose. Unless you show some code, there is not much more to say.

如果您在CSS中使用:hover的意思,并且可以达到预期的效果,那就去做吧.如果对于某个问题有非JS解决方案,请始终选择该解决方案.

If you mean :hover in CSS and you can achieve the desired effect with it, go for it. If there is a non-JS solution for a certain problem, always choose this one.

这篇关于在JQuery中,将鼠标悬停在鼠标悬停上有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆