# touch-position

> get current touch/mouse position

Latest version **2.0.0** (published 2016-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install touch-position
pnpm add touch-position
yarn add touch-position
bun add touch-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.0.0 |
| Published | 2016-03-28 |
| First published | 2014-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | touch, mouse, position, move, mousemove, touchmove, touchstart, window, vector |

## Links

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

## Dependencies (2)

- [events](https://npm.io/package/events.md) ^1.0.2
- [mouse-event-offset](https://npm.io/package/mouse-event-offset.md) ^3.0.2

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-03-28
- 1.1.1 — 2016-03-28
- 1.1.0 — 2015-11-16
- 1.0.3 — 2014-11-17
- 1.0.2 — 2014-11-01
- 1.0.1 — 2014-11-01
- 1.0.0 — 2014-11-01

## README

# touch-position

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Gets the current mouse/touch position as a 2-component vector. By default, attaches mouse and touch events to `window`.

```js
var position = require('touch-position')();

//inside your render loop...
function render () {
  drawSprite(position[0], position[1]);
}
```

*Note:* Version 2.x and above no longer supports IE <= 8.

## Usage

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

#### `position = touchPosition([opt])`

Returns a `position` array with the mouse or current finger's `[ x, y ]` position. Options:

- `element` the element to attach the events to, defaults to `window`
- `touchstart` whether to change position on `touchstart` and `mousedown` events as well (default true)
- `position` the initial position to start with (i.e. before any events are triggered), default is `[0, 0]`

#### `emitter = touchPosition.emitter([opt])`

The same as above, but returns an `EventEmitter` so you can handle move events:

```js
var touch = require('touch-position').emitter()
touch.on('move', handleMove)

console.log(touch.position) // the current [x,y] position
```

#### `emitter.dispose()`

Removes any attached event listeners from `element` when you no longer need it. After calling this method, `touch.position` will no longer update and the `move` event will stop firing.

```js
var touch = require('touch-position').emitter()

touch.dispose()
```

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/touch-position/blob/master/LICENSE.md) for details.

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