]> source.dussan.org Git - jquery.git/commitdiff
Event: fix incorrect window bug with scrollTop/Left in iframes
authorAditya Raghavan <araghavan3@gmail.com>
Sun, 21 Dec 2014 02:52:17 +0000 (21:52 -0500)
committerOleg Gaidarenko <markelog@gmail.com>
Tue, 23 Dec 2014 21:33:00 +0000 (00:33 +0300)
Fixes gh-1945
Closes gh-1959

src/offset.js
test/unit/offset.js

index 69e571f7fcb204254f5872dac2fce8e01513a92b..f4b478f1004047ca40984947887d3936555f427c 100644 (file)
@@ -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 {
index 2c21f5055223012625f9d1fe2e5c54049b001a3f..7771df17e6c5ab54056c5554ccab7115b2e891ba 100644 (file)
@@ -531,4 +531,19 @@ test("fractions (see #7730 and #7885)", function() {
        div.remove();
 });
 
+test("iframe scrollTop/Left (see gh-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()" );
+});
+
 })();