何时选择mouseover()和hover()函数? [英] When to choose mouseover() and hover() function?

查看:104
本文介绍了何时选择mouseover()和hover()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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事件,或触发 该事件在一个元素上.
  • From the official jQuery documentation

    • .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.

      呼叫$(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屋!

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