Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate jquery not working

I do have a small issue with my jQuery Code

Uncaught TypeError: undefined is not a function

<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>

Do you have any idea what is the problem?

Best regards

Goldiman

like image 662
goldiman Avatar asked Mar 18 '26 22:03

goldiman


1 Answers

The problem is because your functions are returning a boolean value of false, which does not have a then() method.

To chain the calls to your functions you need to return the promise from the calls you make to animate(). Try this:

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)
});

Note that it appears that both AnimateCloud() and AnimateCloud2() contain the same logic and could be improved.

like image 90
Rory McCrossan Avatar answered Mar 20 '26 11:03

Rory McCrossan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!