Skip to content

Commit 49833f7

Browse files
committed
Revert "Offset: account for scroll when calculating position"
This reverts commit 2d71594. This commit provoked new issues: gh-2836, gh-2828. At the meeting, we decided to revert offending commit (in all three branches - 2.2-stable, 1.12-stable and master) and tackle this issue in 3.x. Fixes gh-2828
1 parent 9cb89bf commit 49833f7

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

src/offset.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,8 @@ jQuery.fn.extend( {
144144
}
145145

146146
// Add offsetParent borders
147-
// Subtract offsetParent scroll positions
148-
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ) -
149-
offsetParent.scrollTop();
150-
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true ) -
151-
offsetParent.scrollLeft();
147+
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
148+
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
152149
}
153150

154151
// Subtract parent offsets and element margins

test/unit/offset.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ testIframe( "offset/table", "table", function( $, window, document, assert ) {
406406
} );
407407

408408
testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
409-
assert.expect( 30 );
409+
assert.expect( 24 );
410410

411411
assert.equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" );
412412
assert.equal( $( "#scroll-1" ).offset().left, 7, "jQuery('#scroll-1').offset().left" );
@@ -462,17 +462,6 @@ testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
462462
assert.notEqual( $().scrollLeft( null ), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
463463
assert.strictEqual( $().scrollTop(), undefined, "jQuery().scrollTop() testing getter on empty jquery object" );
464464
assert.strictEqual( $().scrollLeft(), undefined, "jQuery().scrollLeft() testing getter on empty jquery object" );
465-
466-
// Tests position after parent scrolling (#15239)
467-
$( "#scroll-1" ).scrollTop( 0 );
468-
$( "#scroll-1" ).scrollLeft( 0 );
469-
assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
470-
assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
471-
472-
$( "#scroll-1" ).scrollTop( 5 );
473-
$( "#scroll-1" ).scrollLeft( 5 );
474-
assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
475-
assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
476465
} );
477466

478467
testIframe( "offset/body", "body", function( $, window, document, assert ) {
@@ -486,6 +475,7 @@ testIframe( "offset/body", "body", function( $, window, document, assert ) {
486475

487476
QUnit.test( "chaining", function( assert ) {
488477
assert.expect( 3 );
478+
489479
var coords = { "top": 1, "left": 1 };
490480
assert.equal( jQuery( "#absolute-1" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
491481
assert.equal( jQuery( "#non-existent" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );

0 commit comments

Comments
 (0)