jQuery .animate() callback infinite loop

前端 未结 5 641
余生分开走
余生分开走 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条回答
  •  梦谈多话
    2021-02-11 00:47

    In the second case, you're calling the function directly, instead of passing it as a parameter.

    start() will call start immediately, and pass the return value of that to .animate(). This causes the infinite self recursion.

提交回复
热议问题