Skip to content

Instantly share code, notes, and snippets.

@fitsum
Created February 7, 2020 18:42
Show Gist options
  • Select an option

  • Save fitsum/2c801245c45f11d2e432e7fa105ccd20 to your computer and use it in GitHub Desktop.

Select an option

Save fitsum/2c801245c45f11d2e432e7fa105ccd20 to your computer and use it in GitHub Desktop.
getting mousemove direction for custom cursor
//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