SHIFT + D

Hover

Updated on September 20, 2024Source codeTests

createHover is a factory that returns Recognizeable effects for recognizing hover.

A hover starts with a mouseover event, and is denied by a mouseout event.

While the mouse is still over the target element, createHover continuously recognizes the gesture at a rate of 60fps. The gesture is recognized when the mouse has been over the element for a minimum duration, which is configurable.

Create hover

Call createHover with these parameters to create your mouseover and mouseout effects:

Parameter
Type
Required
Description
options
Object
no
Options to customize the behavior of the mouseover and mouseout effects. See the Options section for more guidance.

Options

Option
Type
Default
Description
minDuration
number
0
The minimum millisecond duration of the hover, in milliseconds.
onOver
Function
undefined

A function that is called when the mouse is over the target element.

onOver receives the hover hook API as its only parameter.

onOut
Function
undefined

A function that is called when the mouse leaves the target.

onOut receives the hover hook API as its only parameter.

Hook API

The hook API is an object that is passed to the onOver and onOut options as their only parameter. It contains the following properties:

Property
Type
Description
status
string
The status of the sequence. One of recognized, denied, or recognizing.
metadata
Object
Metadata about the sequence. See the Metadata section for more guidance.
sequence
Array
The sequence of events that have occurred so far.

Metadata

Your created hover effects store data in the Recognizeable instance's metadata property.

Hover metadata includes all pointer metadata.

Using with Listenable

The easiest way to use createHover with Listenable is to use the Hover class, which is a very minimal subclass of Listenable that handles configuration for you.

Here's an example of how to use Hover to nicely combine createHover with Listenable:

import { Hover } from '@baleada/logic'

const hover = new Hover([hoverOptions])

hover.listen(() => {
  console.log(hover.metadata.duration)
})

Recognizeable effectsKeychord

Edit doc on GitHub

ON THIS PAGE

HoverCreate hoverOptionsHook APIMetadataUsing with Listenable