简体   繁体   English

在d3中添加元素后,为什么.duration会充当.delay?

[英]Why would .duration act as .delay after appending an element in d3?

I have been building a simple lightweight progress bar widget in d3, and ran across something odd when I tried to set up transitions for it: 我一直在d3中构建一个简单的轻量级进度条小部件,并在尝试为其设置过渡时遇到了奇怪的事情:

http://codepen.io/emoody/pen/oJFGI?editors=101 http://codepen.io/emoody/pen/oJFGI?editors=101

the chunk in question is: 有问题的块是:

  enter //the name of my d3 function
  .append("div")
    .attr("class", "progress")
    .style("width",0)
  .transition()
    .duration(1500)
    .style("width", function(d) { return x(d) * (100/maxRange) + "%"; });

Instead of starting the transition immediately and then animating out to full width over 1500ms, it waits 1500ms then animates at the default duration. 它没有立即开始过渡,而是在1500ms内动画出全宽,而是等待1500ms,然后以默认持续时间进行动画处理。 (you can see the behavior in the linked pen) (您可以在链接的笔中看到行为)

My guess and that of a colleague is that it's actually transitioning some other element with no actual changes first and then this one, causing the appearance of a delay, but I can't figure out why that would be. 我的猜测和一位同事的猜测是,它实际上是在过渡其他元素而没有任何实际更改,然后再过渡,导致出现延迟,但我不知道为什么会这样。

The problem is that you've put a transition in your CSS that's interfering. 问题是您在CSS中添加了干扰的过渡。 In particular 尤其是

transition: all 500ms;

is changing the transition you're trying to set up in D3. 正在更改您要在D3中设置的转换。

Removing this CSS fixes the problem. 删除此CSS可解决此问题。 Complete demo here . 在此处完成演示。

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

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