From 073a71037e205bbb34909a016a111145e61318a9 Mon Sep 17 00:00:00 2001 From: fay Date: Mon, 30 Jul 2018 20:00:16 +0800 Subject: [PATCH] update --- src/core/jquery.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/jquery.js b/src/core/jquery.js index d234a7255..9fef84c4a 100644 --- a/src/core/jquery.js +++ b/src/core/jquery.js @@ -9390,13 +9390,24 @@ jQuery.fn.offset = function( options ) { // If we don't have gBCR, just use 0,0 rather than error // BlackBerry 5, iOS 3 (original iPhone) - if ( typeof elem.getBoundingClientRect !== core_strundefined ) { - box = elem.getBoundingClientRect(); - } + // if ( typeof elem.getBoundingClientRect !== core_strundefined ) { + // box = elem.getBoundingClientRect(); + // } + // 解决transform下的offset问题 + var el = elem, + offsetLeft = 0, + offsetTop = 0; + + do{ + offsetLeft += el.offsetLeft; + offsetTop += el.offsetTop; + + el = el.offsetParent; + } while( el ); win = getWindow( doc ); return { - top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ), - left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 ) + top: offsetTop + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ), + left: offsetLeft + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 ) }; };