JSFiddle - React, Tailwind, and code Playground
HTML
<div id="canvas_container"></div>
JavaScript
// my custom Queue class
var Queue = function() {
this.actionCount = 0;
this.actions = [];
var self = this;
self._cb = function() {
if (++self.actionCount != self.actions.length) self.run();
};
};
Queue.prototype.run = function() {
this.actions[this.actionCount](this._cb);
};
Queue.prototype.add = function(fn) {
this.actions.push(fn);
};
var canvas = Raphael('canvas_container', 322, 273),
points = [ [110,265], [110,7], [7,151], [300,151] ],
mCircle = canvas.circle(points[0][0],points[0][1],10).attr({stroke: "#999", "stroke-width": 4}),
path = [],
circles = [],
queue = new Queue();
// function to generate each set of animation
var fn = function(index) {
var cPath = path[index], cCircle = circles[index],
x1 = points[index][0],
x2 = points[index+1][0],
y1 = points[index][1],
y2 = points[index+1][1];
return function(cb) {
cPath.animate({path:'M'+x1+' '+y1+' L'+x2+' '+y2},500,'easeOut');
mCircle.animate({cx:x2,cy:y2},500,'easeOut');
cCircle.attr({fill: "#fff", r: 12}).animate({fill: "#77bf00", r: 8}, 500, cb);
};
};
for (var i = 0; i < points.length - 1; i++) {
circles[i] = canvas.circle(points[i][0],points[i][1],7).attr({stroke: "none", fill: "#666"});
path[i] = canvas.path('M'+points[i][0]+' '+points[i][1]).attr({
stroke: '#828282',
'stroke-dasharray': "--",
'stroke-linecap': "butt",
'stroke-width': 1,
'fill-opacity': 0
});
queue.add(fn(i));
}
queue.run();