jQuery .animate() callback infinite loop

前端 未结 5 721
余生分开走
余生分开走 2021-02-11 00:18

A simple question: Why can I do this

var start = function() {
    $(\'#element\').animate({}, 5000, \'linear\', start);
}

but not this

5条回答
  •  萌比男神i
    2021-02-11 00:35

    In the second example, you are basically doing a recursive call to start().

    What you want to do is pass the function start itself, like you are doing in your first example. Your second example is only providing the result of calling start().

提交回复
热议问题