内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
这是目前的情况:
vis.selectAll('circle.prospect') .on("mouseover", function(d) { console.log(d); d3.selectAll('circle.prospect').transition().style('opacity','0.5'); d3.select(this).attr('opacity','1.0'); });
这是一个简单例子 :
d3.selectAll("circle.prospect:not(#" + this.id + ")"); d3.selectAll("circle.prospect:not(." + someUniqueClassFrom(d) + ")"); d3.selectAll("circle.prospect:not([uniqueAttr=" + this.getAttribute('uniqueAttr') + "])");
DOM属性:
vis.selectAll('circle.prospect') .on("mouseover", function(d) { this.id = 'temp-' + Math.random(); d3.selectAll('circle.prospect:not(#' + this.id + ')').transition().style('opacity','0.5'); d3.select(this).attr('opacity','1.0'); this.id = ''; });
可以尝试使用这样的方法:
vis.selectAll('circle.prospect').on("mouseover", function(d) { var circleUnderMouse = this; d3.selectAll('circle.prospect').transition().style('opacity',function () { return (this === circleUnderMouse) ? 1.0 : 0.5; }); });