34 lines
646 B
JavaScript
34 lines
646 B
JavaScript
export class Pointer {
|
|
static #x;
|
|
static #y;
|
|
|
|
static init() {
|
|
this.#x = 0;
|
|
this.#y = 0;
|
|
|
|
window.addEventListener('mousemove', this.mouseMove);
|
|
window.addEventListener('mousedown', this.mouseDown);
|
|
window.addEventListener('mouseup', this.mouseUp);
|
|
}
|
|
|
|
static set pos({ x, y }) {
|
|
this.#x = x;
|
|
this.#y = y;
|
|
}
|
|
static get pos() {
|
|
return { x: this.#x, y: this.#y };
|
|
}
|
|
|
|
static mouseMove = (e) => {
|
|
this.pos = { x: e.pageX, y: e.pageY };
|
|
};
|
|
|
|
static mouseDown = (e) => {
|
|
this.pos = { x: e.pageX, y: e.pageY };
|
|
};
|
|
|
|
static mouseUp = (e) => {
|
|
this.pos = { x: e.pageX, y: e.pageY };
|
|
};
|
|
}
|