在(此)之后在d3中选择元素

时间:2014-04-28 16:43:43

标签: javascript d3.js

在d3中,我根据它们的动画制作元素。

.on('mouseover', function (d, i) {
    d3.selectAll('rect')
        .attr('y', function() {
            // affects all <rect> elements
            // I have tried
            if (source.length > (i + 1)) {
                console.log(i);
            }
        }

    d3.select(this)
        .attr('y' function() {
            // affects only the mouseover element
        }

    // since above didn't work, maybe some other selection method will?
    d3.select(AllThingsAfterthis)
        .attr('y' function() {
            // some other values
        }
})

我使用on.('mouseover')事件来确定两种状态:

d3.selectAll('rect')

d3.select(this)

我想知道的是如何仅在分组中this之后选择元素。

rect 1 -> .selectAll
rect 2 -> .selectAll
rect 3 -> this
rect 4 -> how do I target this?
rect 5 -> or this specifically?

1 个答案:

答案 0 :(得分:1)

您可以使用.nextSibling执行此操作:

.on("mouseover", function() {
    var node = this;
    while(node = node.nextSibling) {
        d3.select(node)...;
    }
})

完整演示here