我需要解决这个问题,但不想依赖setTimeout(当浏览器被最小化时,定时器可能会表现异常,并且通常看起来不正确地使用Raphael)。
因此,受trampolines的启发,我制作了一个动画队列。
一般策略是将匿名函数推入队列中,要求在函数的某个地方,animations.next
要么直接调用,要么给动画来触发。
animations = function() {
var animationQueue = []
, obj = {}
obj.push = function(fn) {
animationQueue.push(fn)
}
obj.next = function() {
if (animationQueue.length !== 0) {
animationQueue.shift().call()
}
}
return obj
}()
然后,你可以做这样的事情了几声:
animations.push(function() {
paper.circle(x, y, 2)
.attr('fill', '#fff')
.animate({r: radius}, animationSpeed, animations.next)
})
最后,在不管它是你正在做到底,叫animations.next()
启动链。
感谢oli。我会看看这个,看看它是否有意义 – Alex 2011-12-27 18:28:05
我还不确定你是如何做到这一点的,但它确实有效。谢谢! – Alex 2011-12-27 18:46:11
@亚历克斯很高兴它帮助 - 如果您认为需要一些阐述,请让我知道,我可以更新答案。 – oli 2011-12-28 02:14:41