Created
February 7, 2020 18:42
-
-
Save fitsum/2c801245c45f11d2e432e7fa105ccd20 to your computer and use it in GitHub Desktop.
getting mousemove direction for custom cursor
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
| //TODO: add cursor bg and rotate script. can't tell what's happening without visual | |
| let lastCoords = []; | |
| const handleDir = e => { | |
| let xDiff, yDiff, currCoords = [e.x, e.y]; | |
| if ( lastCoords.length !== 0 ){ | |
| xDiff = currCoords[0] - lastCoords[0]; | |
| yDiff = currCoords[1] - lastCoords[1]; | |
| } | |
| lastCoords = currCoords; | |
| let rads = yDiff > 0 ? Math.atan(xDiff/yDiff) : yDiff < 0 ? Math.atan(yDiff/xDiff) : null; | |
| let degrees = typeof rads !== 'null' ? (rads*(180/Math.PI)) : 'no dice'; | |
| console.log(`Angle: ${degrees}`); | |
| } | |
| document.addEventListener('mousemove', handleDir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment