D3.js:连续运行转换? [英] D3.js: run a transition continuously?

查看:150
本文介绍了D3.js:连续运行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在D3.js中连续运行转换?

How can I run a transition continuously in D3.js?

例如,我想更改正文颜色从红色到蓝色,再回来,不断(我不,那将是可怕的,但与它一起去)。

For example, say I want to change the body colour from red to blue and back again, continuously (I don't, that would be horrendous, but go with it).

这是我会做一次:

d3.select("body").transition().duration(1000).style("background-color", "red");

我如何连续做?

最近的例子我看到使用 d3.timer ,但我不知道如果有一个更好的方法来做到。

The closest examples I have seen use d3.timer, but I am not sure if there is a better way to do it.

推荐答案

您可以使用 transition.each() 和结束事件。代码看起来像下面这样。

You can use transition.each() and the "end" event. The code would look something like the following.

function myTrans() {
    d3.select("body").transition().duration(1000).style("background-color", "red")
      .each("end", function() {
        d3.select(this).transition().duration(1000).style("background-color", "blue")
          .each("end", function() { myTrans(); });
      });
}

这篇关于D3.js:连续运行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆