pointer-lock
pointer-lock api exposed as an event emitter that emits readable streams
of mouse movement data. automatically handles adding appropriate mousedown/up
event listeners on the targeted element. tries to reuse objects instead of creating
new objects, to keep garbage generation low. may sing you songs, if you're nice
enough to it.
var lock = require('pointer-lock')
, my_element = document.getElementById('element')
if(!lock.available())
return alert('not available!')
var pointer = lock(my_element)
pointer.on('attain', function(movements) {
var initial = {x: movements.x, y: movements: y}
movements.on('data', function(move) {
initial.x += move.dx
initial.y += move.dy
initial.t += move.dt
})
movements.on('close', function() {
})
})
pointer.on('release', function() {
})
pointer.on('error', function() {
})
pointer.on('needs-fullscreen', function() {
var fullscreen = require('fullscreen')
, fs = fullscreen(my_element)
fs.once('attain', function() {
pointer.request()
})
fs.request()
})
pointer.request()
pointer.release()
pointer.target()
pointer.destroy()
license
MIT