对于以下d3
代码:
var previousElement = d3.select(this);
console.log(previousElement.attr("style"));
Run Code Online (Sandbox Code Playgroud)
结果如下:
fill: red;
Run Code Online (Sandbox Code Playgroud)
要么
fill: rgb(152, 223, 138);
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能得到这个元素的确切颜色,这样我就可以做出如下判断:
if ( elementColor == 'red')
Run Code Online (Sandbox Code Playgroud)
要么
if (elementColor == 'rgb(152, 223, 138)')
Run Code Online (Sandbox Code Playgroud)
我试过了var elementColor = previousElement.attr("style").fill
,它回来了null
.
我相信你想要的previousElement.style('fill')
不是使用.attr('style')
.有关文档,请参阅https://github.com/mbostock/d3/wiki/Selections#style.
您可能还想查看D3 Colors文档,https://github.com/mbostock/d3/wiki/Colors,因为这可能会对您有所帮助.
归档时间: |
|
查看次数: |
4597 次 |
最近记录: |