aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAditya Raghavan <araghavan3@gmail.com>2014-12-20 21:52:17 -0500
committerOleg Gaidarenko <markelog@gmail.com>2014-12-24 00:33:00 +0300
commitd21edb599d8f5f80a3f3ecba5b62311b9cd1a3e6 (patch)
treecfbe4e09b2f5eebb4f4cfb18fd0f6fa5ed642d95
parentd6c97abb744bfe8c67ab9158aecdb5bb1c05e47b (diff)
downloadjquery-d21edb599d8f5f80a3f3ecba5b62311b9cd1a3e6.tar.gz
jquery-d21edb599d8f5f80a3f3ecba5b62311b9cd1a3e6.zip
Event: fix incorrect window bug with scrollTop/Left in iframes
Fixes gh-1945 Closes gh-1959
-rw-r--r--src/offset.js4
-rw-r--r--test/unit/offset.js15
2 files changed, 17 insertions, 2 deletions
diff --git a/src/offset.js b/src/offset.js
index 69e571f7f..f4b478f10 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -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 {
diff --git a/test/unit/offset.js b/test/unit/offset.js
index 2c21f5055..7771df17e 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -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()" );
+});
+
})();