【问题标题】:Graying out an image in D3js在 D3js 中使图像变灰
【发布时间】:2014-12-08 12:21:53
【问题描述】:

我在 D3js 力有向图中使用图像作为节点。在特定事件中,我想将此图像变灰。 有没有办法做到这一点?

我尝试降低不透明度,但效果不佳。

【问题讨论】:

    标签: d3.js force-layout


    【解决方案1】:

    你真的想把它变成灰度吗?

    借用here

    // set up filter
    svg.append('filter')
      .attr('id','desaturate')
      .append('feColorMatrix')
      .attr('type','matrix')
      .attr('values',"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0");
    
    // then on the nodes to gray apply it
    node.append("image")
      .attr("xlink:href", "https://stackoverflow.com/favicon.ico")
      .style("filter", function(d, i) {
          if (i % 2 == 0) {
            return ("filter", "url(#desaturate)");
          } else {
            return "";
          }
        });
    

    例如here

    【讨论】:

    • 有效!非常感谢:)
    • 您能简要解释一下解决方案吗?我不明白过滤器的属性
    • @Natasha,见here
    猜你喜欢
    • 2010-09-22
    • 2015-05-28
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多