Calculates mouse speed during the mousemove
event.
var MouseSpeed = require("mouse-speed");
var speed = new MouseSpeed();
speed.init(onCalcSpeed);
var onCalcSpeed = function() {
var speedX = speed.speedX;
var speedY = speed.speedY;
// do anything you want with speed values
console.log(speedX, speedY);
};
Create a new instance of mouse-speed in your project.
The speed values are accessed through the speedX
and speedY
properties on the instance.
The function passed to the instance will fire on every mousemove event.
speed.destroy(onDestroyFunc);
var onDestroyFunc = function() {
console.log("destroyed");
};
To remove the event listener, call destroy
on the instance of mouse-speed.
An optional function can be passed that will be called when the event listener is removed
MIT, see LICENSE.md for details.