Skip to content

Instantly share code, notes, and snippets.

@akoGit
Created January 3, 2024 23:56
Show Gist options
  • Save akoGit/3090bc1e2de2ec9322bd8ce39df6e1bd to your computer and use it in GitHub Desktop.
Save akoGit/3090bc1e2de2ec9322bd8ce39df6e1bd to your computer and use it in GitHub Desktop.
export default class Pointer {
constructor() {
if (instance) return instance
this.px = 0
this.py = 0
instance = this
this.init()
}
static getInstance() {
if (!instance) {
instance = new Pointer()
}
return instance
}
static get x() {
return Pointer.getInstance().px
}
static get y() {
return Pointer.getInstance().py
}
init() {
document.addEventListener('pointermove', this.onPointerMove.bind(this))
}
onPointerMove(e) {
this.px = e.pageX
this.py = e.pageY
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment