带有浮点数或小数值的jQuery.css('width') [英] jQuery.css('width') with a floating point or decimal value
问题描述
我已将Chrome的宽度设置为330px,然后手动设置宽度。当我用 jQuery.css('width')
读取宽度时,它返回为329.77777767181396px。
有谁知道为什么这是默认的浮点数,或者不管它是什么,而不是一个整数?
Thanks
如果您对此感到好奇,可以参考下面的w3c规范。
http://www.w3.org/ TR / CSS21 / syndata.html#length-units
浮动值在页面呈现时被四舍五入,确切值存储在内存并用于其子元素计算。例如,如果您的div为105.4999px,则呈现为105px,那么宽度为50%的子元素将以.5 * 100.4999而不是.5 * 100计算。
完成整个关于它的信息,它们被称为 subpixel ,你可以通过John Resig的(jQuery创建者)文章进一步阅读关于子像素问题的文章。
http://ejohn.org/blog/sub -pixel-problems-in-css /
I've set the width of a div to 330px by inspecting it with Chrome and then setting the width manually. When I read the width back with jQuery.css('width')
it comes back as 329.77777767181396px.
Does anyone know why this is defaulting to floating point, or whatever it is, instead of an integer?
Thanks
you can refer to the w3c specification below if you are really curious about this
http://www.w3.org/TR/CSS21/syndata.html#length-units
the floating values are rounded when the page is rendered, the exact values are stored in the memory and used for its child element calculations. For example, if your div is 105.4999px it is rendered to 105px, it's child elements with a width of 50% will be calculated as .5*100.4999 instead of .5*100.
to complete the whole information about this they are called as subpixel and you can have further reading with John Resig's(jQuery creator) article about the problems with subpixels
http://ejohn.org/blog/sub-pixel-problems-in-css/
这篇关于带有浮点数或小数值的jQuery.css('width')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!