我试图用stroke-dashoffset
和stroke-dasharray
属性动画线。这是一个复杂的图与圆圈和线路连接器。我用Snapsvg,这里是我的身影,这是简化的,例如:扣SVG动画不工作
<svg version="1.1" id="fImg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 345 320">
<g id="balls">
<circle cx="125" cy="9.3" r="6.7"/>
<circle cx="230.2" cy="63.5" r="6.7"/>
<circle cx="211.6" cy="18.3" r="6.7"/>
<circle cx="292.6" cy="63.5" r="6.7"/>
</g>
<g id="lines">
<line class="st0" x1="103.8" y1="11.6" x2="125" y2="9.3"/>
<line class="st0" x1="103.8" y1="11.6" x2="115.8" y2="44.9"/>
<line class="st0" x1="103.8" y1="11.6" x2="85.9" y2="32.4"/>
<line class="st0" x1="85.9" y1="32.4" x2="115.8" y2="44.9"/>
</g>
</svg>
我使用捕捉功能为界设置属性和动画它。 lineDrow
- 为线回调函数,但仅.animate({.....}, 1000)
之前,它的工作原理:
var balls = Snap("#balls");
balls.attr({
fill:'rgba(0,0,0,0)'
}).animate({
fill: '#ccc'
}, 2000, mina.easeout, lineDraw);
function lineDraw() {
var lines = document.querySelectorAll("#lines line");
for (var i = 0; i < lines.length; i++) {
var line = Snap(lines[i]),
x = Math.ceil(line.getTotalLength());
line.attr({
'strokeDasharray': x,
'strokeDashoffset': x,
'stroke-width': 1,
'stroke-linecap':'round',
'stroke': '#ccc'
}).animate({
'strokeDasharray': 0,
'strokeDashoffset': 0
}, 1000);
}
}
这让我起皱!怎么了?