diff options
author | Michał Gołębiowski <m.goleb@gmail.com> | 2015-07-02 01:20:18 +0200 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2015-07-07 18:09:45 +0200 |
commit | b60b26e18477d21fa5ec9c6572e114fc5d441730 (patch) | |
tree | a37a0e2b53c1fb3986c59b1ee3d5bfee59ce294e /src | |
parent | 84ccf2606c6b97d5875774bf774f9f2aae950ae7 (diff) | |
download | jquery-b60b26e18477d21fa5ec9c6572e114fc5d441730.tar.gz jquery-b60b26e18477d21fa5ec9c6572e114fc5d441730.zip |
CSS: Make .css("width") & .css("height") return fractional values
Fixes gh-1724
Closes gh-2439
Diffstat (limited to 'src')
-rw-r--r-- | src/css.js | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/css.js b/src/css.js index 373fdcb7e..859985f9d 100644 --- a/src/css.js +++ b/src/css.js @@ -108,21 +108,23 @@ function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) { function getWidthOrHeight( elem, name, extra ) { // Start with offset property, which is equivalent to the border-box value - var valueIsBorderBox = true, - val = name === "width" ? elem.offsetWidth : elem.offsetHeight, + var val, + valueIsBorderBox = true, styles = getStyles( elem ), isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box"; + // Support: IE <= 11 only + // Running getBoundingClientRect on a disconnected node + // in IE throws an error. + if ( elem.getClientRects().length ) { + val = elem.getBoundingClientRect()[ name ]; + } + // Support: IE11 only // In IE 11 fullscreen elements inside of an iframe have // 100x too small dimensions (gh-1764). if ( document.msFullscreenElement && window.top !== window ) { - // Support: IE11 only - // Running getBoundingClientRect on a disconnected node - // in IE throws an error. - if ( elem.getClientRects().length ) { - val = Math.round( elem.getBoundingClientRect()[ name ] * 100 ); - } + val *= 100; } // Some non-html elements return undefined for offsetWidth, so check for null/undefined @@ -309,7 +311,13 @@ jQuery.each([ "height", "width" ], function( i, name ) { // Certain elements can have dimension info if we invisibly show them // but it must have a current display style that would benefit return rdisplayswap.test( jQuery.css( elem, "display" ) ) && - elem.offsetWidth === 0 ? + // Support: Safari 8+ + // Table columns in Safari have non-zero offsetWidth & zero + // getBoundingClientRect().width unless display is changed. + // Support: IE <= 11 only + // Running getBoundingClientRect on a disconnected node + // in IE throws an error. + ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ? swap( elem, cssShow, function() { return getWidthOrHeight( elem, name, extra ); }) : |