Skip to content

Instantly share code, notes, and snippets.

@k1sul1
Created May 11, 2020 13:30
Show Gist options
  • Save k1sul1/bda93e717cb30d6c0ebfcbe7a6d7c4cb to your computer and use it in GitHub Desktop.
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.
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