Socket
Socket
Sign inDemoInstall

touch-position

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    touch-position

get current touch/mouse position


Version published
Weekly downloads
1.4K
increased by8.24%
Maintainers
1
Install size
52.1 kB
Created
Weekly downloads
 

Readme

Source

touch-position

stable

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

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

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:

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.

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

touch.dispose()

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Last updated on 28 Mar 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc