简体   繁体   English

d3转换错误

[英]d3 transition error

I am probably making a rookie D3 mistake here, but I am trying to use D3 to make an animated change in an existing HTML element. 我可能在这里犯了一个菜鸟D3错误,但是我试图使用D3在现有HTML元素中进行动画更改。

So let's say I have the following HTML 假设我有以下HTML

<div id="label">Hello</div>

And then I am trying to change this with animated D3 as follows: 然后,我尝试使用动画D3进行如下更改:

d3.select("#label").transition().duration(1000).html("World");

I get the following error 我收到以下错误

"Object [object Array] has no method 'html'"

When I leave out the transition all works well: 当我忽略过渡时,一切都很好:

d3.select("#label").html("world");

What am I doing wrong here? 我在这里做错了什么?

If you're looking to do something like fade out the "hello" and then fade in the "world", you can do something like: 如果您想做一些事情,例如淡出“ hello”然后淡入“ world”,则可以执行以下操作:

var $label = d3.select("#label");
$label.transition().duration(1000).style('opacity', 0);
$label.transition().delay(1000).duration(1000).text("World").style('opacity', 1);

However, note that the text method is applied immediately at the beginning of the second transition and will only work for plain-text, not html. 但是,请注意, text方法将在第二次转换开始时立即应用,并且仅适用于纯文本,不适用于html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM