ujs/src/pointer.js
2023-05-10 01:28:36 +03:00

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 };
};
}