D3.js 圆脉冲的d3连续跃迁
我正在努力在d3中实现一个简单的连续转换——当我将鼠标悬停在一个节点上时,我希望另一个圆的笔划(固定在页面的其他地方)在大小2和4之间来回转换,直到悬停结束 我在这里找到了一个非常接近的帖子:。特别是最后一条与连续脉冲效应相关的评论: 基于该实现,我的节点悬停函数的内部如下所示D3.js 圆脉冲的d3连续跃迁,d3.js,D3.js,我正在努力在d3中实现一个简单的连续转换——当我将鼠标悬停在一个节点上时,我希望另一个圆的笔划(固定在页面的其他地方)在大小2和4之间来回转换,直到悬停结束 我在这里找到了一个非常接近的帖子:。特别是最后一条与连续脉冲效应相关的评论: 基于该实现,我的节点悬停函数的内部如下所示 d3.selectAll('.fixedCircles').each( function (d) { if (d.name == "circleToPulse") { //selects the c
d3.selectAll('.fixedCircles').each(
function (d) {
if (d.name == "circleToPulse") { //selects the circle I want to pulse, since there's lots of fixed circles
//this correctly returns the stroke-width of the circle I want to pulse
var currentStrokeWidth = d3.select(this).attr("stroke-width");
//if I un-comment this, it will correctly update the circle I want to pulse
//d3.select(this).transition().duration(500).attr('stroke-width', 15);
var theCircle = d3.select(this);
repeat();
function repeat() {
theCircle = theCircle.transition()
.duration(500)
.attr("stroke-width", currentStrokeWidth+2)
.transition()
.duration(500)
.attr('stroke-width', currentStrokeWidth)
.ease('sine')
.each("end", repeat);
}
}
}
);
有了这个解决方案,什么也不会发生。我尝试过在+2的情况下更改笔划宽度大小,但仍然没有任何效果。我如此困惑的原因是,正如我的注释代码所提到的,我可以在repeat函数之外正确地更新固定节点笔划宽度
非常感谢任何人对我可能在这里做错了什么的想法-谢谢 该死,对不起!这是一个愚蠢的字符串与int的比较-在attr设置中添加值(而不是currentStrokeWidth)效果非常好。很高兴你得到了它,你可以回答自己的问题,然后将其标记为已接受