javascript - How to detect mouseenter direction on a specific element -
i have function detects direction of mouse enter. returns integer (0-3) each section illustrated below.

i'm trying figure out how alter function produce output based on illustration:

basically, want figure out if user entering image left or right. i've had few attempts @ trial , error, i'm not @ type of math.
i've set jsfiddle console output example.
the function determine direction is:
function determinedirection($el, pos){ var w = $el.width(), h = $el.height(), x = (pos.x - $el.offset().left - (w/2)) * (w > h ? (h/w) : 1), y = (pos.y - $el.offset().top - (h/2)) * (h > w ? (w/h) : 1); return math.round((((math.atan2(y,x) * (180/math.pi)) + 180)) / 90 + 3) % 4; } where pos object: {x: e.pagex, y: e.pagey}, , $el jquery object containing target element.
replace return math.round((((math.atan2(y,x) * (180/math.pi)) + 180)) / 90 + 3) % 4; return (x > 0 ? 0 : 1);
another option better (simpler idea):
function determinedirection($el, pos){ var w = $el.width(), middle = $el.offset().left + w/2; return (pos.x > middle ? 0 : 1); }
Comments
Post a Comment