@@ -71,13 +71,21 @@ function RemoteFunctions(experimental) {
7171 }
7272
7373 // compute the screen offset of an element
74- function _screenOffset ( element , key ) {
75- var bounds = element . getBoundingClientRect ( ) ;
76- if ( key === "offsetLeft" ) {
77- return bounds . left + window . pageXOffset ;
74+ function _screenOffset ( element ) {
75+ var elemBounds = element . getBoundingClientRect ( ) ,
76+ body = window . document . body ,
77+ offsetTop ,
78+ offsetLeft ;
79+
80+ if ( window . getComputedStyle ( body ) . position === "static" ) {
81+ offsetLeft = elemBounds . left + window . pageXOffset ;
82+ offsetTop = elemBounds . top + window . pageYOffset ;
7883 } else {
79- return bounds . top + window . pageYOffset ;
84+ var bodyBounds = body . getBoundingClientRect ( ) ;
85+ offsetLeft = elemBounds . left - bodyBounds . left ;
86+ offsetTop = elemBounds . top - bodyBounds . top ;
8087 }
88+ return { left : offsetLeft , top : offsetTop } ;
8189 }
8290
8391 // set an event on a element
@@ -114,8 +122,9 @@ function RemoteFunctions(experimental) {
114122 }
115123
116124 // compute the position on screen
117- var x = _screenOffset ( this . element , "offsetLeft" ) ;
118- var y = _screenOffset ( this . element , "offsetTop" ) + this . element . offsetHeight ;
125+ var offset = _screenOffset ( this . element ) ,
126+ x = offset . left ,
127+ y = offset . top + this . element . offsetHeight ;
119128
120129 // create the container
121130 this . body = document . createElement ( "div" ) ;
@@ -239,9 +248,11 @@ function RemoteFunctions(experimental) {
239248
240249 highlight . className = HIGHLIGHT_CLASSNAME ;
241250
251+ var offset = _screenOffset ( element ) ;
252+
242253 var stylesToSet = {
243- "left" : _screenOffset ( element , "offsetLeft" ) + "px" ,
244- "top" : _screenOffset ( element , "offsetTop" ) + "px" ,
254+ "left" : offset . left + "px" ,
255+ "top" : offset . top + "px" ,
245256 "width" : elementBounds . width + "px" ,
246257 "height" : elementBounds . height + "px" ,
247258 "z-index" : 2000000 ,
0 commit comments