mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Dimensions: ignore transforms when retrieving width/height
Close gh-3561 Fixes gh-3193
This commit is contained in:
parent
fc34dbc271
commit
c920ff6e32
22
src/css.js
22
src/css.js
@ -128,26 +128,13 @@ function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
|
|||||||
|
|
||||||
function getWidthOrHeight( elem, name, extra ) {
|
function getWidthOrHeight( elem, name, extra ) {
|
||||||
|
|
||||||
// Start with offset property, which is equivalent to the border-box value
|
// Start with computed style
|
||||||
var val,
|
var valueIsBorderBox,
|
||||||
valueIsBorderBox = true,
|
|
||||||
styles = getStyles( elem ),
|
styles = getStyles( elem ),
|
||||||
|
val = curCSS( elem, name, styles ),
|
||||||
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
||||||
|
|
||||||
// Support: IE <=11 only
|
// Fall back to uncomputed css if necessary
|
||||||
// Running getBoundingClientRect on a disconnected node
|
|
||||||
// in IE throws an error.
|
|
||||||
if ( elem.getClientRects().length ) {
|
|
||||||
val = elem.getBoundingClientRect()[ name ];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some non-html elements return undefined for offsetWidth, so check for null/undefined
|
|
||||||
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
|
|
||||||
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
|
|
||||||
if ( val <= 0 || val == null ) {
|
|
||||||
|
|
||||||
// Fall back to computed then uncomputed css if necessary
|
|
||||||
val = curCSS( elem, name, styles );
|
|
||||||
if ( val < 0 || val == null ) {
|
if ( val < 0 || val == null ) {
|
||||||
val = elem.style[ name ];
|
val = elem.style[ name ];
|
||||||
}
|
}
|
||||||
@ -164,7 +151,6 @@ function getWidthOrHeight( elem, name, extra ) {
|
|||||||
|
|
||||||
// Normalize "", auto, and prepare for extra
|
// Normalize "", auto, and prepare for extra
|
||||||
val = parseFloat( val ) || 0;
|
val = parseFloat( val ) || 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Use the active box-sizing model to add/subtract irrelevant styles
|
// Use the active box-sizing model to add/subtract irrelevant styles
|
||||||
return ( val +
|
return ( val +
|
||||||
|
@ -527,4 +527,15 @@ QUnit.test( "outside view position (gh-2836)", function( assert ) {
|
|||||||
parent.scrollTop( 400 );
|
parent.scrollTop( 400 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
QUnit.test( "width/height on element with transform (gh-3193)", function( assert ) {
|
||||||
|
|
||||||
|
assert.expect( 2 );
|
||||||
|
|
||||||
|
var $elem = jQuery( "<div style='width: 200px; height: 200px; transform: scale(2);' />" )
|
||||||
|
.appendTo( "#qunit-fixture" );
|
||||||
|
|
||||||
|
assert.equal( $elem.width(), 200, "Width ignores transforms" );
|
||||||
|
assert.equal( $elem.height(), 200, "Height ignores transforms" );
|
||||||
|
} );
|
||||||
|
|
||||||
} )();
|
} )();
|
||||||
|
Loading…
Reference in New Issue
Block a user