The extension's defaults are available as reference. Also note that the extension instance gets extended with the options.
interval is the millis to wait before deciding intent. 300
is the
default to reduce more thrashing.
sensitivity is the pixel threshold for mouse travel between polling
intervals. With the minimum sensitivity threshold of 1, the mouse must
not move between intervals. With higher values yield more false positives.
2
is the default.
The events dispatched are the name-spaced enter
and leave
events. They
try to match system mouse events where possible and include values for:
pageX
, pageY
, relatedTarget
.
To summarize the implementation, the _onMouseOver
handler is the start of
the intent 'life-cycle', with state being the default (via _resetState
).
It records the mouse coordinates, sets up a delayed intent check, which is
one of the possible updates done by _updateState
, and is based on the
distance traveled since _timeout
was set. All event handlers guard
against unneeded checking, with _onMouseOut
and _onMouseOver
also using
_checkEventElement
as a filter.
Meanwhile, about every frame, the _onMouseMove
handler tracks the current
mouse coordinates. If the _onMouseOut
handler runs before the delayed
check, the check and subsequent behavior get canceled as state resets to
default. Otherwise, if the check of the stored mouse coordinates against
sensitivity
passes, an enter
event gets dispatched, ensuring a leave
event will too during _onMouseOut
.
HLF Hover Intent Extension
Tests
The
HoverIntent
extension normalizes DOM events associated with mouse enter and leave interaction. It prevents the 'thrashing' of attached behaviors (ex: non-cancel-able animations) when matching mouse input arrives at frequencies past the threshold. It is heavily inspired by Brian Cherne's jQuery plugin of the same name (github.com/briancherne/jquery-hoverIntent).