JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q49751F
  • License MIT

Mouse speed calculated on mouse move.

Package Exports

  • mouse-speed

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mouse-speed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mouse-speed

Calculates mouse speed during the mousemove event, returning x and y speed values.

NPM

Usage

mouse-speed can be used in two ways:

speed(e)

const mouseSpeed = require('mouse-speed');

window.addEventListener('mousemove', (event) => {
  const speed = mouseSpeed(event);
  console.log(speed.x, speed.y);
})

Put mouse-speed in a mousemove event handler and pass it the event object.

Speed is calculated and returned as an object with x and y values.

speed(e, object)

const mouseSpeed = require('mouse-speed');

const speedTracker = {};

window.addEventListener('mousemove', (event) => {
  const speed = mouseSpeed(event, speedTracker);
  console.log(speedTracker.speedX, speedTracker.speedY);
})

Optionally, an object can be passed to it.

This object will now have two new values, accessible as speedX and speedY.

License

MIT, see LICENSE.md for details.