mouse-position
A module for getting the current mouse position on an element, designed for use in games and animations.
Last updated 2 years ago by noffle .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mouse-position 
SYNC missed versions from official npm registry.

mouse-position experimental

A module for getting the current mouse position on an element, designed for use in games and animations.

Usage

NPM

mouse = mousePosition([element], [listener])

Start watching element for mousemove events. If you don't pass an element, mouse will watch the entire browser window.

listener will attach the listener event to another element – helpful, for example, to catch movement across a larger area but still receive positions relative to element.

mouse[0]

The current horizontal position of the mouse, in pixels.

mouse[1]

The current vertical position of the mouse, in pixels.

mouse.prev[0]

The previous horizontal position of the mouse, in pixels.

mouse.prev[1]

The previous vertical position of the mouse, in pixels.

mouse.on('move', callback(event))

Called every time the mouse is moved anywhere on the targeted element.

mouse.flush()

Call this method at the end of each frame to update the prevX and prevY values – you won't get mousemove events every frame, so if you don't update this you might get incorrect values.

mouse.dispose()

Call this method to remove the internal mousemove event listener and any move callbacks on the mouse object.

License

MIT. See LICENSE.md for details.

Current Tags

  • 2.1.0                                ...           latest (2 years ago)

6 Versions

  • 2.1.0                                ...           2 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.0                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
  • 0.0.0                                ...           7 years ago
Downloads
Today 1
This Week 1
This Month 8
Last Day 0
Last Week 4
Last Month 20
Dependencies (1)
Dev Dependencies (1)

Copyright 2014 - 2017 © taobao.org |