2.0.0 • Published 10 years ago
touch-position v2.0.0
touch-position
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
position = touchPosition([opt])
Returns a position array with the mouse or current finger's [ x, y ] position. Options:
elementthe element to attach the events to, defaults towindowtouchstartwhether to change position ontouchstartandmousedownevents as well (default true)positionthe 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] positionemitter.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.
