Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbce13b7

Browse files
authored
CSS: MakeoffsetHeight( true ), etc. include negative margins
This regressed ingh-3656 as the added logic to include scroll guttersin `.innerWidth()` / `.innerHeight()` didn't take negative margins intoaccount. This broke handling of negative margins in`.offsetHeight( true )` and `.offsetWidth( true )`. To fix it, calculatemargin delta separately and only add it after the scroll gutteradjustment logic.Fixesgh-3982Closesgh-5234Refgh-3656
1 parentbcaeb00 commitbce13b7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

‎src/css.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function setPositiveNumber( _elem, value, subtract ) {
4646
functionboxModelAdjustment(elem,dimension,box,isBorderBox,styles,computedVal){
4747
vari=dimension==="width" ?1 :0,
4848
extra=0,
49-
delta=0;
49+
delta=0,
50+
marginDelta=0;
5051

5152
// Adjustment may not be necessary
5253
if(box===(isBorderBox ?"border" :"content")){
@@ -56,8 +57,10 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed
5657
for(;i<4;i+=2){
5758

5859
// Both box models exclude margin
60+
// Count margin delta separately to only add it after scroll gutter adjustment.
61+
// This is needed to make negative margins work with `outerHeight( true )` (gh-3982).
5962
if(box==="margin"){
60-
delta+=jQuery.css(elem,box+cssExpand[i],true,styles);
63+
marginDelta+=jQuery.css(elem,box+cssExpand[i],true,styles);
6164
}
6265

6366
// If we get here with a content-box, we're seeking "padding" or "border" or "margin"
@@ -108,7 +111,7 @@ function boxModelAdjustment( elem, dimension, box, isBorderBox, styles, computed
108111
))||0;
109112
}
110113

111-
returndelta;
114+
returndelta+marginDelta;
112115
}
113116

114117
functiongetWidthOrHeight(elem,dimension,extra){

‎test/unit/dimensions.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ QUnit.test( "outerWidth()", function( assert ) {
240240
});
241241

242242
QUnit.test("outerHeight()",function(assert){
243-
assert.expect(12);
243+
assert.expect(14);
244244

245245
var$div,div,
246246
$win=jQuery(window),
@@ -268,6 +268,11 @@ QUnit.test( "outerHeight()", function( assert ) {
268268
$div.css("display","none");
269269
assert.equal($div.outerHeight(true),94,"Test hidden div with padding, border and margin with margin option");
270270

271+
$div.css("display","");
272+
$div.css("margin","-10px");
273+
assert.equal($div.outerHeight(),74,"Test with padding, border and negative margin without margin option");
274+
assert.equal($div.outerHeight(true),54,"Test with padding, border and negative margin with margin option");
275+
271276
// reset styles
272277
$div.css({"position":"","display":"","border":"","padding":"","width":"","height":""});
273278

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp