CSS: Make .css("width") & .css("height") return fractional values

Fixes gh-1724
Closes gh-2439
This commit is contained in:
Michał Gołębiowski
2015-07-02 01:20:18 +02:00
parent 84ccf2606c
commit b60b26e184
3 changed files with 86 additions and 25 deletions

View File

@@ -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 );