Created
February 19, 2018 10:32
-
-
Save andrIvash/0ca5c74b8f2340485290e539113d3809 to your computer and use it in GitHub Desktop.
get direction of mouse
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
| 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