Get the mouse movement direction and speed (using requestAnimationFrame)
$ npm install mouse-movement
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();
Coming soon