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.

example 1

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

example 2

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

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -