简体   繁体   English

d3js selectAll元素是否受CSS样式影响?

[英]d3js selectAll elements by its CSS style?

Is there a way to select all circle with style visibility===visible ? 有没有一种方法可以选择所有样式visibility===visible circle Something like this: svg.selectAll("circle").filter(function(d) { return this.style.visibility === 'visible'; }) 像这样的东西: svg.selectAll("circle").filter(function(d) { return this.style.visibility === 'visible'; })

You can use d3.selectAll to select all circle svgs ( https://github.com/mbostock/d3/wiki/Selections#d3_selectAll ). 您可以使用d3.selectAll选择所有圆形svgs( https://github.com/mbostock/d3/wiki/Selections#d3_selectAll )。

This is going to return a 2 dimensional array. 这将返回一个二维数组。 It's essentially an array containing arrays of what you selected. 它实际上是一个包含所选数组的数组。 Assuming you have 25 circles: 假设您有25个圈子:

circs = d3.selectAll("circle") // here circs may be [Array[25]]
circs = circs[0] //now circs is an array of circles

Now all you need to do is filter based on the computed style for that element. 现在,您需要做的就是根据该元素的计算样式进行过滤。 Check out this answer for how you'd do that :) 查看此答案以了解您的操作方法:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM