mirror of
https://github.com/jquery/jquery.git
synced 2026-02-07 19:14:55 -05:00
CSS: Make .css("width") & .css("height") return fractional values
Fixes gh-1724 Closes gh-2439
This commit is contained in:
@@ -846,6 +846,51 @@ testIframeWithCallback( "css('width') should work correctly before document read
|
||||
}
|
||||
);
|
||||
|
||||
( function() {
|
||||
var supportsFractionalGBCR,
|
||||
qunitFixture = document.getElementById( "qunit-fixture" ),
|
||||
div = document.createElement( "div" );
|
||||
div.style.width = "3.3px";
|
||||
qunitFixture.appendChild( div );
|
||||
supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed(1) === "3.3";
|
||||
qunitFixture.removeChild( div );
|
||||
|
||||
test( "css('width') and css('height') should return fractional values for nodes in the document", function() {
|
||||
if ( !supportsFractionalGBCR ) {
|
||||
expect( 1 );
|
||||
ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
|
||||
return;
|
||||
}
|
||||
|
||||
expect( 2 );
|
||||
|
||||
var el = jQuery( "<div class='test-div'></div>" ).appendTo( "#qunit-fixture" );
|
||||
jQuery( "<style>.test-div { width: 33.3px; height: 88.8px; }</style>" ).appendTo( "#qunit-fixture" );
|
||||
|
||||
equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
|
||||
"css('width') should return fractional values" );
|
||||
equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
|
||||
"css('height') should return fractional values" );
|
||||
} );
|
||||
|
||||
test( "css('width') and css('height') should return fractional values for disconnected nodes", function() {
|
||||
if ( !supportsFractionalGBCR ) {
|
||||
expect( 1 );
|
||||
ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
|
||||
return;
|
||||
}
|
||||
|
||||
expect( 2 );
|
||||
|
||||
var el = jQuery( "<div style='width: 33.3px; height: 88.8px;'></div>" );
|
||||
|
||||
equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
|
||||
"css('width') should return fractional values" );
|
||||
equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
|
||||
"css('height') should return fractional values" );
|
||||
} );
|
||||
} )();
|
||||
|
||||
test("certain css values of 'normal' should be convertable to a number, see #8627", function() {
|
||||
expect ( 3 );
|
||||
|
||||
|
||||
@@ -258,10 +258,12 @@ test("child of a hidden elem (or unconnected node) has accurate inner/outer/Widt
|
||||
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
|
||||
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
|
||||
|
||||
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
|
||||
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
|
||||
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
|
||||
equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
|
||||
// Support: IE 10-11, Edge
|
||||
// Child height is not always decimal
|
||||
equal( $divChild.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "child of a hidden element height() is wrong see #9441" );
|
||||
equal( $divChild.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "child of a hidden element innerHeight() is wrong see #9441" );
|
||||
equal( $divChild.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "child of a hidden element outerHeight() is wrong see #9441" );
|
||||
equal( $divChild.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
|
||||
|
||||
// tests that child div of an unconnected div works the same as a normal div
|
||||
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
|
||||
@@ -269,10 +271,12 @@ test("child of a hidden elem (or unconnected node) has accurate inner/outer/Widt
|
||||
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
|
||||
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
|
||||
|
||||
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #9441" );
|
||||
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #9441" );
|
||||
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #9441" );
|
||||
equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
|
||||
// Support: IE 10-11, Edge
|
||||
// Child height is not always decimal
|
||||
equal( $divUnconnected.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "unconnected element height() is wrong see #9441" );
|
||||
equal( $divUnconnected.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "unconnected element innerHeight() is wrong see #9441" );
|
||||
equal( $divUnconnected.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "unconnected element outerHeight() is wrong see #9441" );
|
||||
equal( $divUnconnected.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "unconnected element outerHeight( true ) is wrong see #9300" );
|
||||
|
||||
// teardown html
|
||||
$divHiddenParent.remove();
|
||||
@@ -329,10 +333,12 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
|
||||
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
|
||||
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
|
||||
|
||||
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #10413" );
|
||||
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
|
||||
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
|
||||
equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
|
||||
// Support: IE 10-11, Edge
|
||||
// Child height is not always decimal
|
||||
equal( $divChild.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "child of a hidden element height() is wrong see #10413" );
|
||||
equal( $divChild.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "child of a hidden element innerHeight() is wrong see #10413" );
|
||||
equal( $divChild.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "child of a hidden element outerHeight() is wrong see #10413" );
|
||||
equal( $divChild.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
|
||||
|
||||
// tests that child div of an unconnected div works the same as a normal div
|
||||
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
|
||||
@@ -340,10 +346,12 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
|
||||
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
|
||||
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
|
||||
|
||||
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #10413" );
|
||||
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
|
||||
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
|
||||
equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
|
||||
// Support: IE 10-11, Edge
|
||||
// Child height is not always decimal
|
||||
equal( $divUnconnected.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "unconnected element height() is wrong see #10413" );
|
||||
equal( $divUnconnected.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "unconnected element innerHeight() is wrong see #10413" );
|
||||
equal( $divUnconnected.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "unconnected element outerHeight() is wrong see #10413" );
|
||||
equal( $divUnconnected.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "unconnected element outerHeight( true ) is wrong see #10413" );
|
||||
|
||||
// teardown html
|
||||
$divHiddenParent.remove();
|
||||
|
||||
Reference in New Issue
Block a user