eme*_*his 6 javascript firefox animation svg d3.js
我正在使用D3.js来操纵一些SVG元素.我学到了(艰难的)新版本的FireFox并没有真正处理D3的力布局.所以我切换到一个简单的旋转,它在STILL运行蹩脚的Firefox.在下面的代码中,group1
是<circle>
我动态创建的200个svg元素的数组:
function orbit( target, first ) {
/* Other easing options here: https://github.com/mbostock/d3/wiki/Transitions#wiki-d3_ease */
var ease = ( first ) ? 'sin-in' : 'linear';
target
.transition()
.duration(40000)
.ease( ease )
.attrTween("transform", rotTween)
.each('end', function(){ orbit( group1, false ); } );
function rotTween() {
var i = d3.interpolate(0, 360);
return function(t) {
return "rotate(" + i(t) + ","+width/2+","+height/2+")";
};
}
}
orbit( group1, true );
Run Code Online (Sandbox Code Playgroud)
它在Chrome中非常流畅,但它像Firefox中的Choo Choo火车一样突然出现.
根据要求,以下是如何group1
选择:
var makeNode = function(coeficient, x, y) {
coeficient = coeficient || 1;
return {
radius: (Math.random() * coeficient ).toFixed(2),
cx: function() { return x || Math.round(Math.random()*width) },
cy: function() { return y || Math.round(Math.random()*height) }
}
};
var nodes1 = d3.range(300).map( function(){ return makeNode(1.9); } );
var nodes2 = d3.range(700).map( function(){ return makeNode(.6); } );
// var nodes2 = [];
var svg = d3.select('#sky_svg');
var group1 = svg.append('g').attr("class", "group1");
var group2 = svg.append('g').attr("class", "group2");
var addNodes = function(group, nodes) {
for (var i=0; i<nodes.length; i++){
var node = nodes[i];
var circle = group.append('circle');
circle
.attr("r", node.radius )
.attr("cx", node.cx )
.attr("cy", node.cy )
.attr("stroke-width", 8 )
.attr("stroke", "transparent")
.style("fill", "#FFFFFF");
}
}
addNodes( group1, nodes1 );
addNodes( group2, nodes2 );
Run Code Online (Sandbox Code Playgroud)
我也一直在使用 FireFox 渲染 IE/Chrome 处理 svg 转换时遇到问题。关注帖子:
Google 搜索:“寻找在 Firefox 中速度较慢的 SVG”
您还可以搜索:Firefox 的 Gecko 渲染引擎+SVG,发现 Firefox 在响应式 SVG 渲染方面表现不佳。
我的建议是继续向 FireFox 施加压力,以解决动态 SVG 中的这一不良性能问题。
归档时间: |
|
查看次数: |
2951 次 |
最近记录: |