SHIFT + D

Mouserelease

Updated on September 20, 2024Source codeTests

createMouserelease is a factory that returns Recognizeable effects for recognizing mouse releases.

A mouse release is a sequence of a mousedown and a mouseup, and allows for mousemove in between those events, but denies the event on mouseout.

createMouserelease attempts to recognize the gesture when mouseup fires. The gesture is recognized at on mouseup if the mouse has been down for a minimum duration and has moved a minimum distance, both of which are configurable.

Create mouserelease

Call createMouserelease with these parameters to create your mousedown, mouseout, and mouseup effects:

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

Options

Option
Type
Default
Description
minDuration
number
0
The minimum millisecond duration of the mouse release, in milliseconds.
minDistance
number
0
The minimum pixel distance the mouse must move.
minVelocity
number
0
The minimum pixel velocity the mouse must move.
onDown
Function
undefined

A function that is called when the mouse is pressed down.

onDown receives the mouserelease hook API as its only parameter.

onMove
Function
undefined

A function that is called when the mouse moves.

onMove receives the mouserelease hook API as its only parameter.

onOut
Function
undefined

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

onOut receives the mouserelease hook API as its only parameter.

onUp
Function
undefined

A function that is called when the mouse is released.

onUp receives the mouserelease hook API as its only parameter.

Hook API

The hook API is an object that is passed to the onDown, onMove, onOut, and onUp 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 mouserelease effects store data in the Recognizeable instance's metadata property.

Mouserelease metadata includes all pointer metadata.

Using with Listenable

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

Here's an example of how to use Mouserelease to nicely combine createMouserelease with Listenable:

import { Mouserelease } from '@baleada/logic'

const mouserelease = new Mouserelease([mousereleaseOptions])

mouserelease.listen(() => {
  console.log(mouserelease.metadata.velocity)
})

MousepressTouchpress

Edit doc on GitHub

ON THIS PAGE

MousereleaseCreate mousereleaseOptionsHook APIMetadataUsing with Listenable