diff options
author | jeresig <jeresig@gmail.com> | 2010-01-07 14:07:21 -0500 |
---|---|---|
committer | jeresig <jeresig@gmail.com> | 2010-01-07 14:07:21 -0500 |
commit | 4fa00369f00b8ee708c8962135b7aa345e3d30d0 (patch) | |
tree | 55fb2b2ddddd5fe33cf0c2ab5b394af4e6d5ef26 /src/offset.js | |
parent | ebaf374f2ac02e224ff0d0775b9709579404dd58 (diff) | |
download | jquery-4fa00369f00b8ee708c8962135b7aa345e3d30d0.tar.gz jquery-4fa00369f00b8ee708c8962135b7aa345e3d30d0.zip |
Added in support for .offset(Function).
Diffstat (limited to 'src/offset.js')
-rw-r--r-- | src/offset.js | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/offset.js b/src/offset.js index d12921dff..7dd71343e 100644 --- a/src/offset.js +++ b/src/offset.js @@ -7,8 +7,8 @@ if ( "getBoundingClientRect" in document.documentElement ) { } if ( options ) { - return this.each(function() { - jQuery.offset.setOffset( this, options ); + return this.each(function( i ) { + jQuery.offset.setOffset( this, i, options ); }); } @@ -33,8 +33,8 @@ if ( "getBoundingClientRect" in document.documentElement ) { } if ( options ) { - return this.each(function() { - jQuery.offset.setOffset( this, options ); + return this.each(function( i ) { + jQuery.offset.setOffset( this, i, options ); }); } @@ -137,7 +137,7 @@ jQuery.offset = { return { top: top, left: left }; }, - setOffset: function( elem, options ) { + setOffset: function( elem, i, options ) { // set position first, in-case top/left are set even on static elem if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) { elem.style.position = "relative"; @@ -145,11 +145,16 @@ jQuery.offset = { 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 = { - top: (options.top - curOffset.top) + curTop, - left: (options.left - curOffset.left) + curLeft - }; + curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0; + + if ( jQuery.isFunction( options ) ) { + options = options.call( elem, i, curOffset ); + } + + var props = { + top: (options.top - curOffset.top) + curTop, + left: (options.left - curOffset.left) + curLeft + }; if ( "using" in options ) { options.using.call( elem, props ); |