在jQuery动画中仅执行一次完整功能? [英] Execute complete function only once in jQuery animation?

查看:80
本文介绍了在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");
    }
})

演示

这篇关于在jQuery动画中仅执行一次完整功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆