I am new to SVG animations, I looked in to SNAP SVG and other libraries, but I cannot find a way to achieve my goal. I have a SVG file (or the SVG is directly integrated in HTML), that contains multiple paths. I want to show the SVG image, one path at a time, and animate each path like the example at:
To better describe the result I want, please take a look at this image:
This is a svg element that contains 4 paths. I want to show draw each path using javascript (not CSS), one after another, and animate them like:
From left to right, each point at a time. To obtain something like a hand drawn effect of the image.
EDIT: Based on the answer from @ian, I made a jsfiddle showing what I have done so far. It displays all paths one by one, but I want somehow to simulate them as a drawing. So drawing the path between all points so it looks like in the animation above.
The current code works, in sense that it shows all paths, one by one, but it does not "draw them", it just instantly displays them, instead of creating an animation for each point path.
EDIT 2: I now understand the problem with my shape. They are not lines with points, but an object. I need to find a solution to turn the svg path object to a path with points.
https://jsfiddle.net/sodevrom/mvyru6g5/2/
var s = Snap("#svgout");
var svgin = Snap("#svgin");
function Drawing(svgin,transformString, timeBetweenDraws ) {
this.fragment =svgin;
this.pathArray = this.fragment.selectAll('path');
this.group = s.g().transform( transformString ).drag();
this.timeBetweenDraws = timeBetweenDraws;
};
Drawing.prototype.init = function( svgString, transformString ) {
this.group.clear();
this.currentPathIndex = 0;
};
Drawing.prototype.endReached = function() {
if( this.currentPathIndex >= this.pathArray.length ) {
return true;
};
};
Drawing.prototype.callOnFinished = function() {
}
Drawing.prototype.initDraw = function() {
this.init();
this.draw();
};
Drawing.prototype.quickDraw = function() {
this.init();
this.timeBetweenDraws = 0;
this.draw();
};
Drawing.prototype.draw = function() {
if( this.endReached() ) {
if( this.callOnFinished ) {
this.callOnFinished();
return
};
};
var myPath = this.pathArray[ this.currentPathIndex ] ;
this.leng = myPath.getTotalLength();
this.group.append( myPath );
myPath.attr({
"stroke-dasharray": this.leng + " " + this.leng,
"stroke-dashoffset": this.leng
});
this.currentPathIndex++;
myPath.animate({"stroke-dashoffset": 2}, this.timeBetweenDraws, mina.easeout, this.draw.bind( this ) );
};
var myDrawing1=new Drawing( svgin, 'translate(0,400) scale(0.100000,-0.100000)', 800 );
myDrawing1.initDraw();
Any suggestions is appreciated.
Thank you