jQuery 悬停意图检测插件 悬停意图

  • 源码大小:12.82KB
  • 所需积分:1积分
  • 源码编号:19JP-3780
  • 浏览次数:711次
  • 最后更新:2023年07月22日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

一个轻量级但有用的jQuery用户意图检测插件,用于扩展jQuery的悬停方法,该方法会延迟handlerIn函数,直到用户真正想悬停在特定元素上。非常适合防止鼠标指针进入和离开元素时意外触发悬停事件。

如何使用它:

1.在jquery JavaScript库之后加载JavaScript文件“jquery.haverIntent.js”插件,hoverIntent即可使用。

  1. <script src="//code.jquery.com/jquery.min.js"></script>
  2. <script src="jquery.hoverIntent.js"></script>

2.基本用法。就像.hover()方法

  • 手柄输入:函数OR配置对象
  • 手柄输出:用于委托或未定义的函数或选择器
  1. .hoverIntent( handlerIn, handlerOut )
  2. .hoverIntent( handlerInOut )

3.基本用法。有活动委托。

  • 手柄输入:函数OR配置对象
  • 手柄输出:用于委托或未定义的函数或选择器
  • 选择器:选择器OR未定义
  1. .hoverIntent( handlerIn, handlerOut, selector )
  2. .hoverIntent( handlerInOut, selector )

4.使用基本配置对象激活插件。

  1. .hoverIntent({
  2.  
  3. // The number of milliseconds hoverIntent waits between reading/comparing mouse coordinates.
  4. // When the user's mouse first enters the element its coordinates are recorded.
  5. // The soonest the "over" function can be called is after a single polling interval.
  6. // Setting the polling interval higher will increase the delay before the first possible "over" call, but also increases the time to the next point of comparison.
  7. interval: 100,
  8.  
  9. // If the mouse travels fewer than this number of pixels between polling intervals, then the "over" function will be called.
  10. // With the minimum sensitivity threshold of 1, the mouse must not move between polling intervals.
  11. // With higher sensitivity thresholds you are more likely to receive a false positive. Note that hoverIntent r7 and earlier perform this comparison using rectilinear distance, whereas more recent versions compare against Euclidean (straight-line) distance for better accuracy and intuition.
  12. // If you are upgrading from an older version, you may want to verify that the desired behavior is preserved.
  13. sensitivity: 6,
  14.  
  15. // A simple delay, in milliseconds, before the "out" function is called.
  16. // If the user mouses back over the element before the timeout has expired the "out" function will not be called (nor will the "over" function be called).
  17. // This is primarily to protect against sloppy/human mousing trajectories that temporarily (and unintentionally) take the user off of the target element... giving them time to return.
  18. timeout: 0
  19. })

更新日志:

2021-12-14

  • v1.10.2:替换已弃用的jQuery.isFunction

2019-10-06

  • v1.10.1:通过在尝试访问hoverIntent数据之前检查数据来修复可能的比赛条件

2019-02-26

  • v1.10.0版本

2017-09-01

  • v1.9.0版本

预览截图