mouse-movement
v0.0.9
Published
Mouse movement info
Downloads
14
Maintainers
Readme
MouseMovement.js
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