How to organize animation using snap.svg?

I am trying to animate several objects in a sequence using http://snapsvg.io/ .

I want the first object to move, and after the completion of the second object to move, etc.

Instead of the following code, all animations at once.

    var s = Snap("#svg");

    var triangle = s.path("M200 200,L600,500 L200,500 L200,200");

    var triangleClone = triangle.clone();
    triangleClone.animate({'transform' : 'r90,200,200 T400,300'}, 1000);

    var triangleClone2 = triangle.clone();
    triangleClone2.animate({'transform' : 'r180,200,200 T100,700'},1000);

    var triangleClone3 = triangle.clone();
    triangleClone3.animate({'transform' : 'r270,200,200 T-300,400'},1000);

What approach do you need to control when something comes to life? It seems that there is not one call to connect.

+4
source share
2 answers

Snap has callback function after animation, according to docs

If you want to do a few sequentially, you can make it a little easier and create a function in which you simply pass arrays of animation to it (see the example below) ...

var s = Snap("#svg");

var anim1 = function() { 
    triangleClone.animate({'transform' : 'r90,200,200 T400,300'}, 1000, mina.linear, anim2);
}

var anim2 = function() {
    triangleClone2.animate({'transform' : 'r180,200,200 T100,700'},1000, mina.linear, anim3);
}

var anim3 = function() {
    triangleClone3.animate({'transform' : 'r270,200,200 T-300,400'},1000);
}



var triangle = s.path("M200 200,L600,500 L200,500 L200,200");
var triangleClone = triangle.clone();
var triangleClone2 = triangle.clone();
var triangleClone3 = triangle.clone();

anim1();

jsfiddle

, , , ,

+9

async.js ...

:

async.series([
    function(callback) {
     whatever.animate({ transform: "s-1,1t0,200" }, 1000, mina.linear, callback);    
    },
    function(callback) {  
     whatever.animate({ transform: "t500,200s-1,1" }, 1000, mina.linear, callback);    
    },
    function(callback) {  
     whatever.animate({ transform: "t500,200s1,1" }, 1000, mina.linear, callback);    
    },
    function(callback) {  
     whatever.animate({ transform: "t0,200s1,1" }, 1000, mina.linear, callback);    
    }
]);
+1

Source: https://habr.com/ru/post/1534922/


All Articles