小编Tom*_*nes的帖子

D3.js中div中的转换和文本属性

我正在尝试在D3中做一些简单的文本框,并在SO上使用另一个q&a我已经发现我需要使用foreignObject并将文本包装在div中.那一切都很好.我想要做的是通过点击其他东西来更新文本.我可以更新文本本身,但不能更新它的大小或颜色.这不可能是正确的.这是我的代码.

    var svg = d3.select("body")
        .append("svg")
        .attr("width", w)
        .attr("height", h);

//add some text for clicking
    svg.append("text")
    .attr("x", "260")
    .attr("y", "40")
    .attr("font-family","sans-serif")
    .attr("font-size", "18")
    .attr("fill", "black")
    .attr("id", "clickone")
    .text("Click this")
    ;      

//this is the foreignObject with the original text

       svg.append('foreignObject')
           .attr('x', 40)
           .attr('y', 100)
           .attr('width', 180)
           .attr('height', 100)
           .append("xhtml:body")
           .attr("id","words")
           .html('<div style="width: 160px;"><p>Old text old text old text old text old text old text<p></div>');

//and here's the click and transition                  

    svg.select("svg #clickone")
        .on("click", function() {

    svg.select('p')
    .transition()
    .delay(500)
    .text("new text new …
Run Code Online (Sandbox Code Playgroud)

html text transition d3.js

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

d3.js ×1

html ×1

text ×1

transition ×1