javascript - Peculiar behavior on the far right side of <body> -


i'm trying implement custom context menu , means have take care of edges of container (so menu doesn't appear outside of visible boundaries).

so far, simple proof-of-concept works there's weird interaction between conditionals checking if menu outside bottom edge , outside right edge.

 if((context.clientheight + e.pagey) > (body.clientheight)){     context.style.top = (e.pagey - context.clientheight) + "px";  }   if((context.clientwidth + e.pagex) > (body.clientwidth)){     context.style.left = (e.pagex - context.clientwidth) + "px";  } 

alone, each of these conditionals produces intended behavior, except 1 checks right boundary somehow off 16 pixels, can't explain. weird part when leave both conditionals there, on far right , bottom corner there square area cause context menu appear outside it, regardless of click's distance edge. it's if both conditions, menu refuses appear within square, though happy 1 of 2 conditions.

here's fiddle. i'm stumped since occasional console logging of coordinates seems produce expected numbers.

i not sure if related problem in firefox yet in chrome encounter 2 problems:

one textflow makes conditions wrong, since context.clientwidth changes (from 52 40) if reach right edge due text , padding breaks. therefore add:

white-space: nowrap; 

to .menu-item{}

also going encounter problems when facing scrollbars. in experience better change side instead of far right corner middle of page. forked example here: http://jsfiddle.net/ncstjbyq/


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -