From 1d2df772b4d6e5dbf91df6e75f4a1809f7879ab0 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 24 Apr 2017 12:15:39 -0400 Subject: Offset: Use correct offset parents; include all border/scroll values Thanks @anseki Fixes gh-3080 Fixes gh-3107 Closes gh-3096 Closes gh-3487 --- test/data/offset/boxes.html | 99 +++++++++++++++++++++ test/unit/offset.js | 211 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 test/data/offset/boxes.html (limited to 'test') diff --git a/test/data/offset/boxes.html b/test/data/offset/boxes.html new file mode 100644 index 000000000..dbc7a15c0 --- /dev/null +++ b/test/data/offset/boxes.html @@ -0,0 +1,99 @@ + + + + + + Nonempty margin/border/padding/position + + + + + + +
+
relative > relative
+
relative > absolute
+
+
+
absolute > relative
+
absolute > absolute
+
+
+
fixed > relative
+
fixed > absolute
+
+

position:absolute with no top/left values

+ + diff --git a/test/unit/offset.js b/test/unit/offset.js index 5b73ede60..622a7ba90 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -503,6 +503,215 @@ QUnit.test( "chaining", function( assert ) { assert.equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" ); } ); +// Test complex content under a variety of / positioning styles +( function() { + var POSITION_VALUES = [ "static", "relative", "absolute", "fixed" ], + + // Use shorthands for describing an element's relevant properties + BOX_PROPS = + ( "top left marginTop marginLeft borderTop borderLeft paddingTop paddingLeft" + + " style parent" ).split( /\s+/g ), + props = function() { + var propObj = {}; + supportjQuery.each( arguments, function( i, value ) { + propObj[ BOX_PROPS[ i ] ] = value; + } ); + return propObj; + }, + + // Values must stay synchronized with test/data/offset/boxes.html + divProps = function( position, parentId ) { + return props( 8, 4, 16, 8, 4, 2, 32, 16, position, parentId ); + }, + htmlProps = function( position ) { + return props( position === "static" ? 0 : 4096, position === "static" ? 0 : 2048, + 64, 32, 128, 64, 256, 128, position ); + }, + bodyProps = function( position ) { + return props( position === "static" ? 0 : 8192, position === "static" ? 0 : 4096, + 512, 256, 1024, 512, 2048, 1024, position, + position !== "fixed" && "documentElement" ); + }, + viewportScroll = { top: 2, left: 1 }, + + alwaysScrollable = false; + + // Support: iOS <=7 + // Detect viewport scrollability for pages with position:fixed document element + ( function() { + var $iframe = jQuery( "