动画jQuery不起作用

高迪曼

我的jQuery代码确实有一个小问题

未捕获的TypeError:undefined不是函数

<script type="text/javascript">
    function AnimateCloud() {
        $("#cloudAmu").animate({
            "left": "+150%"
        }, 5000, 'linear');
        return false;
    }

    function AnimateCloud2() {
        $("#cloudAmu").animate({
            "right": "+150%"
        }, 5000, 'linear');
        return false;
    }

    $(document).ready(
        AnimateCloud().then(AnimateCloud2())
    );
</script>

你知道是什么问题吗?

最好的祝福

高迪曼

罗里·麦克罗森(Rory McCrossan)

问题是因为您的函数返回的布尔值false,没有then()方法。

要将调用链接到函数,您需要promise从对的调用中返回animate()尝试这个:

function AnimateCloud() {
    return $("#cloudAmu").animate({
        "left": "+150%"
    }, 5000, 'linear').promise();
}

function AnimateCloud2() {
    return $("#cloudAmu").animate({
        "right": "+150%"
    }, 5000, 'linear').promise();
}

$(document).ready(function() {
    AnimateCloud().then(AnimateCloud2)
});

请注意,似乎AnimateCloud()AnimateCloud2()包含相同的逻辑,可以进行改进。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章