DocsHover & overlays
Get started

Search Subtly documentation

Search by a task, helper name or framework.

Hover & overlays

hoverIntent()

Open a preview after a deliberate hover.

Try the example

Move quickly across the project button, then rest on it. The project preview opens after 150 ms of deliberate hover. You can also focus or click the button.

Preview closed. Hover, focus or click to open.

Actual npm package · local demonstrationHover timing needs a desktop pointer

Add it to your project

  1. Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
  2. Connect the behavior. Copy the JavaScript tab and call its exported mount(element) after your component’s elements exist. Replace simulated delays and data operations with your own application code.
  3. Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.

API and lifecycle

Attach hoverIntent(element, callbacks) to delay a mouse preview until pointer movement settles. Defaults are 150 ms opening delay, 120 ms closing delay and a 6 px movement threshold.

Interface
delay=150, closeDelay=120, distance=6; returns cleanup
Lifecycle
The returned cleanup cancels timers and removes pointer listeners. Mount once per trigger and clean up when the trigger or its view is removed.

Accessibility and safety

Implementation notes

Hover is an enhancement. Keep click, focus and keyboard alternatives. Do not hide interactive content merely because a pointer leaves a trigger.

The utility listens to mouse pointer events. Add focus and click/tap activation separately, and keep interactive preview content reachable when moving off the trigger.

What to check

Sweep across the trigger quickly, then hover deliberately. Check focus, tap and click alternatives, and moving the pointer into the preview.