so here, I have a sequence of animations using Raphael:
- fade in curve
- fade in ball 1
- animate ball 1
- fade in ball 2
- animate ball 2
however, with my code, steps 4-5 are initiated WHILE the steps 2-3 are still animating. How do I ensure steps 4 and 5 are initiated after the animations of 1-3 are complete? I’ve tried using setTimeout on my second function (ball2), but no luck.
View on JSFiddle or here:
Raphael("bounce", 640, 480, function () {
var r = this,
p = r.path("M0,77.255c0,0,269.393,37.431,412.96,247.653 c0,0,95.883-149.719,226.632-153.309").attr({stroke: "#666", opacity: 0, "stroke-width": 1}),
len = p.getTotalLength(),
e = r.circle(0, 0, 7).attr({stroke: "none", fill: "#000", opacity:0}).onAnimation(function () {
var t = this.attr("transform");
});
f = r.circle(0, 0, 7).attr({stroke: "none", fill: "#000",opacity:0}).onAnimation(function () {
var t = this.attr("transform");
});
r.customAttributes.along = function (v) {
var point = p.getPointAtLength(v * len);
return {
transform: "t" + [point.x, point.y] + "r" + point.alpha
};
};
e.attr({along: 0});
f.attr({along: 0});
var rotateAlongThePath = true;
function fadecurve(ca,ba,aa,ab){
ca.animate({opacity:1},500);
setTimeout(function(){fadeball(ba,aa,ab);
},1000);
}
function fadeball(ba,aa,ab) {
ba.animate({opacity:1},400);
setTimeout(function(){run(ba, aa,ab);
},1000);
}
function run(ba,aa,ab) {
ba.animate({along: aa}, ab, ">", function () {
ba.attr({along: aa});
});
}
function startbounce() {
fadecurve(p,e,.9,400),
setTimeout(function(){fadeball(f,.8,400);
},1000);
}
startbounce();
});
According to Raphael’s documentation, the animate method takes a callback method as it’s fourth argument. That method could be used to initiate the next animation in your sequence (or after the third animation).
For example.