如何获得不透明后的真实颜色值
我正在使用 jquery 和 css 淡化菜单项的背景颜色和不透明度。但是,我想让背景颜色成为实际的 css 背景颜色:
例如:
css background color: #eabf60
real color after .70 opacity: #ECCD85
我想这也很大程度上取决于不透明元素背后的背景...
有什么想法吗?
I am using jquery and css to fade the background color and opacity of a menu item. However, I want to have the background color be the actual css background color:
For example:
css background color: #eabf60
real color after .70 opacity: #ECCD85
i suppose this also depends largely in part on the background behind the opaque element...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,没有跨浏览器的方法来获取渲染后某个点的颜色。
所以剩下的唯一方法就是模拟这个。获取 CSS 背景颜色和不透明度,然后向上遍历父级,直到找到另一个背景条目。
问题是:您也无法获取颜色的 RGB 值,只能获取 CSS 字符串。所以如果背景颜色是“蓝色”,你就输了。但大多数时候,您应该得到一个像
#ffee00
这样的 7 个字符的字符串,您可以将其转换为 24 位整数(或从 0 到 255 的 3 个整数)。之后,您可以简单地应用不透明度:AFAIK, there is no cross-browser way to get the color of a certain point after rendering.
So the only way left is to simulate this. Get the CSS background color plus the opacity and then walk upwards through your parents until you find another background entry.
The problem: You can't get the RGB values of a color either, only the CSS string. So if the background color is "blue", you loose. But most of the time, you should get a 7-character string like
#ffee00
which you can convert to a 24bit integer (or 3 integers from 0 to 255). After that, you can simply apply the opacity: