javascript - Find the place of a cursor in rectangle -


i don't know how find place part (one of 4 triangles) of cursor in rectangle.

this image more efficient explication :s

enter image description here

im in javascript (so rectangle div, 0,0 placed) have varaibles :

var cursor_x = e.clientx + $(document).scrollleft() var cursor_y = e.clienty + $(document).scrolltop()  var rect_w = $( rectangle ).width() var rect_h = $( rectangle ).height() 

i want know mathematically cursor, in triangle 1, 2, 3 or 4

thx

what think easiest way first normalize y computation same square , check on side of diagonals are...

var ynorm = y * w / h; var s1 = x > ynorm ? 0 : 1; var s2 = (w - x) > ynorm ? 0 : 1; var area = s1*2 + s2; 

the final area variable number between 0 , 3 telling in of 4 parts are.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -