Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
jquery offset: reducing more the code size.
  • Loading branch information
flesler committed May 14, 2008
1 parent ac324c9 commit 831625c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/offset.js
Expand Up @@ -140,7 +140,9 @@ jQuery.fn.extend({

// Create scrollLeft and scrollTop methods
jQuery.each( ['Left', 'Top'], function(i, name) {
jQuery.fn[ 'scroll' + name ] = function(val) {
var method = 'scroll' + name;

jQuery.fn[ method ] = function(val) {
if (!this[0]) return;

return val != undefined ?
Expand All @@ -149,17 +151,17 @@ jQuery.each( ['Left', 'Top'], function(i, name) {
this.each(function() {
this == window || this == document ?
window.scrollTo(
name == 'Left' ? val : jQuery(window)[ 'scrollLeft' ](),
name == 'Top' ? val : jQuery(window)[ 'scrollTop' ]()
!i ? val : jQuery(window).scrollLeft(),
i ? val : jQuery(window).scrollTop()
) :
this[ 'scroll' + name ] = val;
this[ method ] = val;
}) :

// Return the scroll offset
this[0] == window || this[0] == document ?
self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
jQuery.boxModel && document.documentElement[ 'scroll' + name ] ||
document.body[ 'scroll' + name ] :
this[0][ 'scroll' + name ];
self[ i ? 'pageYOffset' : 'pageXOffset' ] ||
jQuery.boxModel && document.documentElement[ method ] ||
document.body[ method ] :
this[0][ method ];
};
});

0 comments on commit 831625c

Please sign in to comment.