Skip to content

Commit

Permalink
Event: fixing incorrect window bug with scrollTop/Left in iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
araghava committed Dec 21, 2014
1 parent d6c97ab commit 3fd7134
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/offset.js
Expand Up @@ -171,8 +171,8 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function(

if ( win ) {
win.scrollTo(
!top ? val : window.pageXOffset,
top ? val : window.pageYOffset
!top ? val : win.pageXOffset,
top ? val : win.pageYOffset
);

} else {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/offset.js
Expand Up @@ -531,4 +531,19 @@ test("fractions (see #7730 and #7885)", function() {
div.remove();
});

test("iframe scrollTop/Left (see #1945)", function() {
expect( 2 );

// Tests scrollTop/Left with iframes
var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument;
jQuery( "#iframe" ).css( "width", "50px" ).css( "height", "50px" );
ifDoc.write( "<div style='width: 1000px; height: 1000px;'></div>" );

jQuery( ifDoc ).scrollTop( 200 );
jQuery( ifDoc ).scrollLeft( 500 );

equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" );
equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" );
});

})();

0 comments on commit 3fd7134

Please sign in to comment.