Created
January 3, 2024 23:56
-
-
Save akoGit/3090bc1e2de2ec9322bd8ce39df6e1bd to your computer and use it in GitHub Desktop.
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 characters
| 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