🌐 AI搜索 & 代理 主页
Skip to content

Commit a495784

Browse files
authored
Dimensions: Improve offsetWidth/offsetHeight fallback
Fixes gh-3698 Fixes gh-3602 Closes gh-3738
1 parent 262acc6 commit a495784

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/css.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,17 @@ function getWidthOrHeight( elem, dimension, extra ) {
163163
valueIsBorderBox = valueIsBorderBox &&
164164
( support.boxSizingReliable() || val === elem.style[ dimension ] );
165165

166-
// Fall back to offsetWidth/Height when value is "auto"
166+
// Fall back to offsetWidth/offsetHeight when value is "auto"
167167
// This happens for inline elements with no explicit setting (gh-3571)
168-
if ( val === "auto" ) {
168+
// Support: Android <=4.1 - 4.3 only
169+
// Also use offsetWidth/offsetHeight for misreported inline dimensions (gh-3602)
170+
if ( val === "auto" ||
171+
!parseFloat( val ) && jQuery.css( elem, "display", false, styles ) === "inline" ) {
172+
169173
val = elem[ "offset" + dimension[ 0 ].toUpperCase() + dimension.slice( 1 ) ];
174+
175+
// offsetWidth/offsetHeight provide border-box values
176+
valueIsBorderBox = true;
170177
}
171178

172179
// Normalize "" and auto

test/unit/dimensions.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,25 @@ QUnit.test( "width/height on an inline element with no explicitly-set dimensions
544544
} );
545545
} );
546546

547+
QUnit.test( "width/height on a table row with phantom borders (gh-3698)", function( assert ) {
548+
assert.expect( 4 );
549+
550+
jQuery( "<table id='gh3698' style='border-collapse: separate; border-spacing: 0;'><tbody>" +
551+
"<tr style='margin: 0; border: 10px solid black; padding: 0'>" +
552+
"<td style='margin: 0; border: 0; padding: 0; height: 42px; width: 42px;'></td>" +
553+
"</tr>" +
554+
"</tbody></table>" ).appendTo( "#qunit-fixture" );
555+
556+
var $elem = jQuery( "#gh3698 tr" );
557+
558+
jQuery.each( [ "Width", "Height" ], function( i, method ) {
559+
assert.equal( $elem[ "outer" + method ](), 42,
560+
"outer" + method + " should match content dimensions" );
561+
assert.equal( $elem[ "outer" + method ]( true ), 42,
562+
"outer" + method + "(true) should match content dimensions" );
563+
} );
564+
} );
565+
547566
QUnit.test( "interaction with scrollbars (gh-3589)", function( assert ) {
548567
assert.expect( 48 );
549568

0 commit comments

Comments
 (0)