admin管理员组文章数量:1297091
So I've been just generating opacity for interactive fading.
I think however, that it's not a good idea to use unrounded values for opacity. If the maximum precision is lower than maximum javascript in precision, the browsers seem to round the value, but consider it changed.
So the question is, what is the maximum precision that makes sense for CSS3 opacity
?
So I've been just generating opacity for interactive fading.
I think however, that it's not a good idea to use unrounded values for opacity. If the maximum precision is lower than maximum javascript in precision, the browsers seem to round the value, but consider it changed.
So the question is, what is the maximum precision that makes sense for CSS3 opacity
?
- 5 I have a hunch this is implementation-dependent. – BoltClock Commented May 24, 2014 at 18:11
- I haven't got any specific evidence, but to keep IE playing nice I've always thought of opacity in decimals between 0 and 1 allowing for 11 possibilities, that isn't much but they guarantee a 'change' – David Barker Commented May 24, 2014 at 18:17
- Just tried with Math.random in Chrome, and setting and getting 16 decimal places doesn't seem like it's an issue, I guess the question is more what would be practical, and what can you actually see the difference of ? – adeneo Commented May 24, 2014 at 18:19
- It should also be noted that jQuery uses around 16-17 decimal places -> jsfiddle/pXqdH/2 – adeneo Commented May 24, 2014 at 18:25
1 Answer
Reset to default 12Opacity allows for basically any number of decimals you'd like, but the issue is that HTML can only ever change its lightness in 256 different ways. So, the most sensitive opacity would be in something black over something white, which would have a visible variety of 256 different hues. This is because the ratio between R, G, and B must always stay the same to maintain the same colour.
So, since the most sensitive colour has 256 different values, the smallest change that would have an effect on the visible output would be 1/256 = 0.00390625
. In theory, that should be the minimum step size for increasing your opacity.
I've tested this, and using a simple colour picker I noticed that in this example fiddle, the bottom div was the only one which had any change of colour. The top 2 divs had the colour #000000
, and the bottom div had the colour #010101
. So, I would say, based on this, that:
- The entered values are not rounded, or if they are, they are always rounded down (floor function)
- The maximum sensitivity for opacity is 3 decimals.
It should be noted that this was all tested in Google Chrome, and like BoltClock said, this might vary per implementation.
本文标签: javascriptWhat is the maximum precision of CSS3 opacityStack Overflow
版权声明:本文标题:javascript - What is the maximum precision of CSS3 opacity? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741648027a2390305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论