aboutsummaryrefslogtreecommitdiffstats
path: root/src/offset.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/offset.js')
-rw-r--r--src/offset.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/offset.js b/src/offset.js
index 6216b69d6..8caab5315 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -133,24 +133,32 @@ jQuery.each( ['Left', 'Top'], function(i, name) {
jQuery.fn[ method ] = function(val) {
if ( !this[0] ) return null;
+
+ var elem = this[0], win = ("scrollTo" in elem && elem.document) ? elem :
+ (elem.nodeName === "#document") ? elem.defaultView || elem.parentWindow :
+ false;
return val !== undefined ?
// Set the scroll offset
this.each(function() {
- this == window || this == document ?
- window.scrollTo(
- !i ? val : jQuery(window).scrollLeft(),
- i ? val : jQuery(window).scrollTop()
+ win = ("scrollTo" in this && this.document) ? this :
+ (this.nodeName === "#document") ? this.defaultView || this.parentWindow :
+ false;
+
+ win ?
+ win.scrollTo(
+ !i ? val : jQuery(win).scrollLeft(),
+ i ? val : jQuery(win).scrollTop()
) :
this[ method ] = val;
}) :
// Return the scroll offset
- this[0] == window || this[0] == document ?
- self[ i ? 'pageYOffset' : 'pageXOffset' ] ||
- jQuery.support.boxModel && document.documentElement[ method ] ||
- document.body[ method ] :
- this[0][ method ];
+ win ?
+ win[ i ? 'pageYOffset' : 'pageXOffset' ] ||
+ jQuery.support.boxModel && win.document.documentElement[ method ] ||
+ win.document.body[ method ] :
+ elem[ method ];
};
});