Copy folder
This commit is contained in:
commit
f40d182e88
7 changed files with 343 additions and 0 deletions
23
js/InputHandler.js
Normal file
23
js/InputHandler.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class InputHandler {
|
||||
constructor(idOfWatchedArea) {
|
||||
const elem = document.getElementById(idOfWatchedArea);
|
||||
|
||||
const handleMouse = ({ offsetX, offsetY }) =>
|
||||
this.setPointerPosition([offsetX, offsetY]);
|
||||
const handleTouch = ({ touches }) =>
|
||||
this.setPointerPosition([touches[0].clientX, touches[0].clientY]);
|
||||
|
||||
elem.addEventListener("mousemove", handleMouse);
|
||||
elem.addEventListener("touchmove", handleTouch);
|
||||
|
||||
this.pointerPosition = [0, 0];
|
||||
}
|
||||
|
||||
setPointerPosition(newPosition) {
|
||||
this.pointerPosition = newPosition;
|
||||
}
|
||||
|
||||
get position() {
|
||||
return this.pointerPosition;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue