diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2023-04-04 16:00:55 +0200 |
---|---|---|
committer | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2023-04-04 16:03:06 +0200 |
commit | 7bb48a0290a20594ea2a5a7b5772e0410a67164c (patch) | |
tree | 79e93f3278d876abce331db41cb9fce2cfe7611d /src/css.js | |
parent | 9ab26aa508c6cca6afa9c6247ee6d50eaed2da77 (diff) | |
download | jquery-7bb48a0290a20594ea2a5a7b5772e0410a67164c.tar.gz jquery-7bb48a0290a20594ea2a5a7b5772e0410a67164c.zip |
CSS: Make `offsetHeight( true )`, etc. include negative margins
This regressed in gh-3656 as the added logic to include scroll gutters
in `.innerWidth()` / `.innerHeight()` didn't take negative margins into
account. This broke handling of negative margins in
`.offsetHeight( true )` and `.offsetWidth( true )`. To fix it, calculate
margin delta separately and only add it after the scroll gutter
adjustment logic.
Fixes gh-3982
Closes gh-5234
Ref gh-3656
(cherry picked from commit bce13b72c1753e16cc0db53ebf0f0456bdcf6b48)
Diffstat (limited to 'src/css.js')
-rw-r--r-- | src/css.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/css.js b/src/css.js index 1e113fde0..1ec1aa8f4 100644 --- a/src/css.js +++ b/src/css.js @@ -51,7 +51,8 @@ function setPositiveNumber( _elem, value, subtract ) { function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computedVal ) { var i = dimension === "width" ? 1 : 0, extra = 0, - delta = 0; + delta = 0, + marginDelta = 0; // Adjustment may not be necessary if ( box === ( isBorderBox ? "border" : "content" ) ) { @@ -61,8 +62,10 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed for ( ; i < 4; i += 2 ) { // Both box models exclude margin + // Count margin delta separately to only add it after scroll gutter adjustment. + // This is needed to make negative margins work with `outerHeight( true )` (gh-3982). if ( box === "margin" ) { - delta += jQuery.css( elem, box + cssExpand[ i ], true, styles ); + marginDelta += jQuery.css( elem, box + cssExpand[ i ], true, styles ); } // If we get here with a content-box, we're seeking "padding" or "border" or "margin" @@ -113,7 +116,7 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed ) ) || 0; } - return delta; + return delta + marginDelta; } function getWidthOrHeight( elem, dimension, extra ) { |