/mouse-movement

Get the mouse movement direction and speed (using requestAnimationFrame)

Primary LanguageJavaScriptMIT LicenseMIT

MouseMovement.js

Github file size GitHub issues npm GitHub license

Get the mouse movement direction and speed (using requestAnimationFrame)

Installation

$ npm install mouse-movement

Usage

Listen for mouse movement on the window

import MouseMovement from 'mouse-movement';

const mouseMovement = new MouseMovement();
mouseMovement.init({mousemoveCallback: mouseMovementCallback});

let mouseMovementCallback = function () {
    console.log(mouseMovement.directionX);
    console.log(mouseMovement.speedX);
    console.log(mouseMovement.directionY);
    console.log(mouseMovement.speedY);
    console.log(mouseMovement.diagonal);
}

Listen for mouse movement on one or more elements

import MouseMovement from 'mouse-movement';

const mouseMovement = new MouseMovement('.element');
mouseMovement.init({mousemoveCallback: mouseMovementCallback});

let mouseMovementCallback = function () {
    console.log(mouseMovement.directionX);
    console.log(mouseMovement.speedX);
    console.log(mouseMovement.directionY);
    console.log(mouseMovement.speedY);
    console.log(mouseMovement.diagonal);
}

Remove all listeners associated with the class

mouseMovement.destroy();

Examples

Coming soon