Created
May 11, 2020 13:30
-
-
Save k1sul1/bda93e717cb30d6c0ebfcbe7a6d7c4cb to your computer and use it in GitHub Desktop.
I spent way too much time digging the correct properties. For future reference.
This file contains 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
function onMouseMove(event, initialX: number, initialY: number) { | |
const { clientX, clientY, movementX, movementY } = event | |
const moving = { | |
left: movementX < 0 | |
right: movementX > 0 | |
up: movementY < 0 | |
down: movementY > 0 | |
} | |
// Use these to determine how much the cursor has moved from initialX & Y | |
const xOffset = clientX - initialX // Negative value means left, positive means right | |
const yOffset = clientY - initialY // Positive value means down, negative means up | |
return { | |
xOffset, yOffset, | |
moving | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment