Skip to content

Commit d21edb5

Browse files
araghavamarkelog
authored andcommitted
Event: fix incorrect window bug with scrollTop/Left in iframes
Fixes jquerygh-1945 Closes jquerygh-1959
1 parent d6c97ab commit d21edb5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/offset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(
171171

172172
if ( win ) {
173173
win.scrollTo(
174-
!top ? val : window.pageXOffset,
175-
top ? val : window.pageYOffset
174+
!top ? val : win.pageXOffset,
175+
top ? val : win.pageYOffset
176176
);
177177

178178
} else {

test/unit/offset.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,19 @@ test("fractions (see #7730 and #7885)", function() {
531531
div.remove();
532532
});
533533

534+
test("iframe scrollTop/Left (see gh-1945)", function() {
535+
expect( 2 );
536+
537+
// Tests scrollTop/Left with iframes
538+
var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument;
539+
jQuery( "#iframe" ).css( "width", "50px" ).css( "height", "50px" );
540+
ifDoc.write( "<div style='width: 1000px; height: 1000px;'></div>" );
541+
542+
jQuery( ifDoc ).scrollTop( 200 );
543+
jQuery( ifDoc ).scrollLeft( 500 );
544+
545+
equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" );
546+
equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" );
547+
});
548+
534549
})();

0 commit comments

Comments
 (0)