所以在这里,我有一系列使用 Raphael 的动画:
- 淡入曲线
- 淡入球 1
- 动画球 1
- 淡入球 2
- 动画球 2
但是,使用我的代码,步骤 4-5 会启动,而步骤 2-3 仍在动画中。如何确保在 1-3 的动画完成后启动第 4 步和第 5 步?我尝试在我的第二个函数(ball2)上使用 setTimeout,但没有运气。
在 JSFiddle或此处查看:
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();
});