Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created February 19, 2018 10:32
Show Gist options
  • Select an option

  • Save andrIvash/0ca5c74b8f2340485290e539113d3809 to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/0ca5c74b8f2340485290e539113d3809 to your computer and use it in GitHub Desktop.
get direction of mouse
var getDirection = function (ev, obj) {
var w = obj.offsetWidth,
h = obj.offsetHeight,
x = (ev.pageX - obj.offsetLeft - (w / 2) * (w > h ? (h / w) : 1)),
y = (ev.pageY - obj.offsetTop - (h / 2) * (h > w ? (w / h) : 1)),
d = Math.round( Math.atan2(y, x) / 1.57079633 + 5 ) % 4;
return d;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment