gpt4 book ai didi

javascript - 如何使用 jQuery 更改创建的 D3 对象的 CSS?

转载 作者:太空宇宙 更新时间:2023-11-04 13:26:48 26 4
gpt4 key购买 nike

我有以下 D3 代码,我想将 CSS 添加到其中:

  // Update the links…
var link = vis.selectAll("path.link")
.data(tree.links(nodes), function(d) { return d.target.id; });

// Enter any new links at the parent's previous position.
link.enter().insert("svg:path", "g")
.attr("class", "link")
.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});
})
.transition()
.duration(duration)
.attr("d", diagonal);

// Transition links to their new position.
link.transition()
.duration(duration)
.attr("d", diagonal);

link.style("stroke", function(d, i){
console.log();
if((i == ((link.size()/2)-1) || i == ((link.size()/2)-2)) && (AMLsIncluded == true)){
return "white";
}
});

我使用以下代码更改 CSS 但没有任何反应:

$(".link path").css({"fill":"none", "stroke":"#ccc", "stroke-width":"1.5px"});

我是否以正确的方式获取 path.link?我曾经将我的 css 放在单独的 .css 文件中,但出于多种原因我需要使其动态化。这在从 CSS 文件导入时有效:

path.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}

我做错了什么?

最佳答案

您需要使用与 D3 代码和 CSS 文件中相同的选择器:

$("path.link").css({"fill":"none", "stroke":"#ccc", "stroke-width":"1.5px"});

关于javascript - 如何使用 jQuery 更改创建的 D3 对象的 CSS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23655893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com