何时选择mouseover()和hover()函数? [英] When to choose mouseover() and hover() function?
问题描述
jQuery .mouseover()
和.hover()
函数之间有什么区别?如果它们完全相同,为什么jQuery会同时使用两者?
What are the differences between jQuery .mouseover()
and .hover()
functions? If they are totally same why jQuery uses both?
推荐答案
摘自jQuery官方文档
-
.mouseover()
将事件处理程序绑定到"mouseover" JavaScript事件,或触发 该事件在一个元素上. .mouseover()
Bind an event handler to the "mouseover" JavaScript event, or trigger that event on an element.-
.hover()
绑定一个或两个处理程序 到匹配的元素,当鼠标指针被执行时 输入和离开元素. .hover()
Bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
From the official jQuery documentation
呼叫$(selector).hover(handlerIn, handlerOut)
是以下方面的简写:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
Calling $(selector).hover(handlerIn, handlerOut)
is shorthand for:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
绑定当鼠标进入元素时要触发的事件处理程序, 或在元素上触发该处理程序.
Bind an event handler to be fired when the mouse enters an element, or trigger that handler on an element.
mouseover
将触发
好吧,虽然mouseenter
仅在指针移入
绑定元素.
mouseover
fires when the pointer moves into the child element as
well, while mouseenter
fires only when the pointer moves into the
bound element.
因此,.mouseover()
与.hover()
是不,出于相同的原因,.mouseover()
与.mouseenter()
是不.
Because of this, .mouseover()
is not the same as .hover()
, for the same reason .mouseover()
is not the same as .mouseenter()
.
$('selector').mouseover(over_function) // may fire multiple times
// enter and exit functions only called once per element per entry and exit
$('selector').hover(enter_function, exit_function)
这篇关于何时选择mouseover()和hover()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!