gpt4 book ai didi

javascript - 动态 url 作为 css 和 D3JS 中伪元素的数据属性

转载 作者:可可西里 更新时间:2023-11-01 13:04:20 26 4
gpt4 key购买 nike

我必须动态更改 css 伪元素中链接列表的图标 url。我认为最好的方法是通过属性传递所选图标的链接,但我无法将其用作 url。

CSS

a[data-icon]:before{
padding-right: 5px;
padding-top: 5px;
content:url(attr(data-icon));
}

D3JS(我在其中检索 iconURL)

 for (var i = 0; i < JSONclassesInfo.typesList.length; i++){
if (JSONclassesInfo.typesList[i].name == type){

temp = JSONclassesInfo.typesList[i].compatible;
iconRoute= JSONclassesInfo.typesList[i].icon;
}
}

for(var i = 0; i < temp.length; i++){
d3.select('.dropdown')
.append("li")
.attr('class','listOpt')
.append('a')
.text(temp[i])
.attr("href","#")
.attr('data-icon',iconRoute);


}

最佳答案

忘记在 URL 的内容中使用 attr() CSS 函数。只需更改此:

 .attr('data-icon',iconRoute);

有了这个:

 .css('background-image',iconRoute);

关于javascript - 动态 url 作为 css 和 D3JS 中伪元素的数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34858946/

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