I'm trying to animate stroke-dasharray
with Snap.svg but didn't get it to work: nothing happens. The goal is to animate a straight line into a dashed line.
SVG
<svg>
<line fill="none" stroke="#008D36" stroke-width="2" stroke-miterlimit="10" x1="175" y1="153" x2="175" y2="21" id="Line"/>
</svg>
CSS
line {
stroke-dasharray: 0,0;
}
Javascript
$(function() {
var s = Snap('svg');
var l = s.select('#Line');
l.animate({'stroke-dasharray':'1,20'}, 500);
});
See this fiddle: /
I'm trying to animate stroke-dasharray
with Snap.svg but didn't get it to work: nothing happens. The goal is to animate a straight line into a dashed line.
SVG
<svg>
<line fill="none" stroke="#008D36" stroke-width="2" stroke-miterlimit="10" x1="175" y1="153" x2="175" y2="21" id="Line"/>
</svg>
CSS
line {
stroke-dasharray: 0,0;
}
Javascript
$(function() {
var s = Snap('svg');
var l = s.select('#Line');
l.animate({'stroke-dasharray':'1,20'}, 500);
});
See this fiddle: http://jsfiddle/u4pxW/5/
Share Improve this question edited Jul 9, 2014 at 10:24 Slevin asked Jul 9, 2014 at 10:10 SlevinSlevin 4,24212 gold badges46 silver badges91 bronze badges 2- Maybe this question may help you: Animate dotted path, one dot after another – Sven Commented Jul 9, 2014 at 10:18
- Hmm, in fact I want to animate a straight line into a dashed line. So I had to draw two lines: one straight line and one dashed line, while the straight line should bee shortener and the dashed line longer. Too plicated/too much code/too much unnecessary SVG code for a simple effect. It seems that this sort of animation isn't possible? – Slevin Commented Jul 9, 2014 at 10:23
1 Answer
Reset to default 5It depends what effect you are going for, but you should be able to animate it. There's a couple of different ways to animate, and maybe for this specific example I would try Snap.animate...
var s = Snap('svg');
var l = s.select('#Line');
Snap.animate(0,20, function( value ) {
l.attr({ 'stroke-dasharray': '1,' + value});
}, 2000);
jsfiddle
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745042945a4607921.html
评论列表(0条)