# mouse-position

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

Latest version **2.1.0** (published 2018-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install mouse-position
pnpm add mouse-position
yarn add mouse-position
bun add mouse-position
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-08-23 |
| First published | 2014-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Hugh Kennedy |
| Maintainers | hughsk, noffle, pconerly |
| Keywords | mouse, position, movement, speed, check, game |

## Links

- npm: https://www.npmjs.com/package/mouse-position
- Repository: https://github.com/hughsk/mouse-position
- Issues: https://github.com/hughsk/mouse-position/issues
- npm.io page: https://npm.io/package/mouse-position

## Dependencies (1)

- [events](https://npm.io/package/events.md) ^1.0.1

## Recent versions

- 2.1.0 (latest) — 2018-08-23
- 2.0.1 — 2016-01-02
- 2.0.0 — 2015-08-04
- 1.0.0 — 2014-06-14
- 0.0.1 — 2014-05-13
- 0.0.0 — 2014-05-13

## README

# mouse-position [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

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

## Usage

[![NPM](https://nodei.co/npm/mouse-position.png)](https://nodei.co/npm/mouse-position/)

### 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](http://github.com/hughsk/mouse-position/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/mouse-position · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
