mouse-speed

2.0.1 • Public • Published

mouse-speed

Calculates mouse speed during the mousemove event.

NPM

Usage

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

License

MIT, see LICENSE.md for details.

Package Sidebar

Install

npm i mouse-speed

Weekly Downloads

5

Version

2.0.1

License

MIT

Unpacked Size

10.5 kB

Total Files

15

Last publish

Collaborators

  • philipbell