Skip to content

Commit a0f5c35

Browse files
committed
Revert "Offset: account for scroll when calculating position"
This reverts commit 0654711. This commit provoked new issues: jquerygh-2836, jquerygh-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 jquerygh-2828
1 parent e7e80fe commit a0f5c35

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

src/offset.js

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

144144
// Add offsetParent borders
145-
// Subtract offsetParent scroll positions
146-
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ) -
147-
offsetParent.scrollTop();
148-
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true ) -
149-
offsetParent.scrollLeft();
145+
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
146+
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
150147
}
151148

152149
// Subtract parent offsets and element margins

test/unit/offset.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ testIframe( "offset/table", "table", function( $, window, document, assert ) {
412412
} );
413413

414414
testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
415-
assert.expect( 28 );
415+
assert.expect( 24 );
416416

417417
// If we're going to bastardize the tests, let's just DO it
418418
var ie = /msie [678]/i.test( navigator.userAgent );
@@ -495,25 +495,6 @@ testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
495495
assert.notEqual( $().scrollLeft( null ), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
496496
assert.strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
497497
assert.strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
498-
499-
// Tests position after parent scrolling (#15239)
500-
$( "#scroll-1" ).scrollTop( 0 );
501-
$( "#scroll-1" ).scrollLeft( 0 );
502-
if ( ie ) {
503-
assert.ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
504-
} else {
505-
assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
506-
}
507-
assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
508-
509-
$( "#scroll-1" ).scrollTop( 5 );
510-
$( "#scroll-1" ).scrollLeft( 5 );
511-
if ( ie ) {
512-
assert.ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
513-
} else {
514-
assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
515-
}
516-
assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
517498
} );
518499

519500
testIframe( "offset/body", "body", function( $, window, document, assert ) {
@@ -528,9 +509,9 @@ testIframe( "offset/body", "body", function( $, window, document, assert ) {
528509
QUnit.test( "chaining", function( assert ) {
529510
assert.expect( 3 );
530511
var coords = { "top": 1, "left": 1 };
531-
equal( jQuery( "#absolute-1" ).offset( coords ).selector, "#absolute-1", "offset(coords) returns jQuery object" );
532-
equal( jQuery( "#non-existent" ).offset( coords ).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
533-
equal( jQuery( "#absolute-1" ).offset( undefined ).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
512+
assert.equal( jQuery( "#absolute-1" ).offset( coords ).selector, "#absolute-1", "offset(coords) returns jQuery object" );
513+
assert.equal( jQuery( "#non-existent" ).offset( coords ).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
514+
assert.equal( jQuery( "#absolute-1" ).offset( undefined ).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
534515
} );
535516

536517
QUnit.test( "offsetParent", function( assert ) {

0 commit comments

Comments
 (0)