width, height, scrollLeft, and scrollTop now work with windows and documents other than just the one it was loaded in (like iframes and popups)
This commit is contained in:
parent
a0d079f430
commit
2adb9b2a0f
2 changed files with 27 additions and 17 deletions
|
@ -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 ];
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue