Created
January 3, 2024 23:56
-
-
Save akoGit/3090bc1e2de2ec9322bd8ce39df6e1bd to your computer and use it in GitHub Desktop.
Revisions
-
akoGit created this gist
Jan 3, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ 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 } }