diff options
author | Brandon Aaron <brandon.aaron@gmail.com> | 2010-03-22 20:11:37 -0400 |
---|---|---|
committer | Brandon Aaron <brandon.aaron@gmail.com> | 2010-03-22 20:11:37 -0400 |
commit | 656fe92178fda539d91fe31965b28bccff484778 (patch) | |
tree | 8a44a5facb9bb8ef805c1f96cbfd4e3cac92c3e0 /src/offset.js | |
parent | 08cf82e88e7a1f88da34ca251335a685889f8765 (diff) | |
download | jquery-656fe92178fda539d91fe31965b28bccff484778.tar.gz jquery-656fe92178fda539d91fe31965b28bccff484778.zip |
Fixed an issue with setting offset of absolutely positioned element that has no position values ("auto"). Fixes #5781.
Diffstat (limited to 'src/offset.js')
-rw-r--r-- | src/offset.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/offset.js b/src/offset.js index 59591caea..0ce4c1979 100644 --- a/src/offset.js +++ b/src/offset.js @@ -150,15 +150,27 @@ jQuery.offset = { }, setOffset: function( elem, options, i ) { + var position = jQuery.curCSS( elem, "position" ); + // set position first, in-case top/left are set even on static elem - if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) { + if ( position === "static" ) { elem.style.position = "relative"; } - var curElem = jQuery( elem ), - curOffset = curElem.offset(), - curTop = parseInt( jQuery.curCSS( elem, "top", true ), 10 ) || 0, - curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0, - props = {}; + + var curElem = jQuery( elem ), + curOffset = curElem.offset(), + curCSSTop = jQuery.curCSS( elem, "top", true ), + curCSSLeft = jQuery.curCSS( elem, "left", true ), + calculatePosition = (position === "absolute" && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1), + props = {}, curPosition = {}, curTop, curLeft; + + // need to be able to calculate position if either top or left is auto and position is absolute + if ( calculatePosition ) { + curPosition = curElem.position(); + } + + curTop = calculatePosition ? curPosition.top : parseInt( curCSSTop, 10 ) || 0; + curLeft = calculatePosition ? curPosition.left : parseInt( curCSSLeft, 10 ) || 0; if ( jQuery.isFunction( options ) ) { options = options.call( elem, i, curOffset ); |