Skip to content
Permalink
Browse files

jquery offset: reducing the code size.

  • Loading branch information
flesler committed May 14, 2008
1 parent f717260 commit ac324c97e319c8a107036e7ce98dff6e5f78a8ba
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/offset.js
@@ -101,23 +101,23 @@ jQuery.fn.offset = function() {

jQuery.fn.extend({
position: function() {
var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
var left = 0, top = 0, results;

if (elem) {
if ( this[0] ) {
// Get *real* offsetParent
offsetParent = this.offsetParent();
var offsetParent = this.offsetParent(),

// Get correct offsets
offset = this.offset();
parentOffset = offsetParent.offset();
// Get correct offsets
offset = this.offset(),
parentOffset = offsetParent.offset();

// Subtract element margins
offset.top -= parseInt( jQuery.curCSS(elem, 'marginTop', true) ) || 0;
offset.left -= parseInt( jQuery.curCSS(elem, 'marginLeft', true) ) || 0;
offset.top -= num( this, 'marginTop' );
offset.left -= num( this, 'marginLeft' );

// Add offsetParent borders
parentOffset.top += parseInt( jQuery.curCSS(offsetParent[0], 'borderTopWidth', true) ) || 0;
parentOffset.left += parseInt( jQuery.curCSS(offsetParent[0], 'borderLeftWidth', true) ) || 0;
parentOffset.top += num( offsetParent, 'borderTopWidth' );
parentOffset.left += num( offsetParent, 'borderLeftWidth' );

// Subtract the two offsets
results = {

0 comments on commit ac324c9

Please sign in to comment.
You can’t perform that action at this time.