3
我有一个应用一些内联样式的div,作为rgba(0,255,0,1)
,我使用...style.borderColor
返回一个带有其颜色值的字符串。如何从window.getComputedStyle()或其他函数返回rgba值?
我注意到如果α通道是1(无透明性)的返回值是仅在rgb
格式,如果在rgba
正确返回代替一些透明度施加像rgba(0,255,0,0.5)
值的颜色。
- 你知道有什么方法可以强制返回
rgba
(带有alpha)吗? - 如果没有我怎么能添加这个值,字符串操作是一个好方法?
var elm = document.querySelector('#target');
console.log(elm.style.borderColor);
<div id="target" style=" width: 150px; height:150px; background-color:red; border-color: rgba(0,255,0,1); border-width: 20px; border-style: solid;"></div>
还有一些有趣的途径,在这个线程跟随。 http://stackoverflow.com/questions/11068240/what-is-the-most-efficient-way-to-parse-a-css-color-in-javascript – lonesomeday
你为什么需要这个?如果您想修改颜色,CSS Color Level 4计划引入功能来修改颜色。 – Oriol
@Oriol有趣的,请你给我一个链接? – Radex