在jQuery动画中仅执行一次完整功能?

在jQuery动画中仅执行一次完整功能?

问题描述:

我正在尝试为某些文本的字体大小设置动画:

I'm trying to animate the font size of some text:

$("p").delay(500).animate({
    "font-size": "+=50"
}, 1000, function() {
    alert("Done");
})​;

这是一个演示.

我想在对<p>进行动画处理后做一些事情,在示例中为alert,但是令人惊讶的是,它为每个<p>运行了它,这不是我想要的.有没有办法使它只运行一次还是不可能?

I want to do something after animating the <p>s, which in the example is alert, but it surprisingly runs it for each <p>, and that's not what I want. Is there a possible way to make it just run once or is it not possible?

var $p = $("p");
var lastIndex = $p.length - 1;

$p.delay(500).animate({
    "font-size": "+=50"
}, 1000, function() {
    if ($p.index($(this)) == lastIndex) {
        alert("Done");
    }
})

演示