Smoothly animate attribute changes to ~3000 Raphael objects at once

后端 未结 4 1742
深忆病人
深忆病人 2021-01-06 03:08

UPDATED QUESTION I\'ve updated this to be a little more succinct..:

In this fiddle: http://jsfiddle.net/pX2Xb/4/ I have some raphael code that draws

4条回答
  •  逝去的感伤
    2021-01-06 03:40

    I don't know why, but D3.js is more efficient when animating a large number of elements at once. You can make them both work seamlessly by creating a Raphael function that receives a set and returns the html objects you want to animate:

    Raphael.st.nodes = function() {
      var elements = [];
      this.forEach(function (i) {
         elements.push(i.node);
      });
      return elements;
    }
    

    And then you let d3 take it from there

    //circleholder is a Raphael set
    elements = circleholder.nodes()
    d3.selectAll(elements)
      .transition()
      .attr("fill", function(d,i){return colours[randomNum(14)]})
      .duration(ANIMATION_DELAY)
    

    Here is the jsfiddle: http://jsfiddle.net/mFecs/

提交回复
热议问题