jQuery .animate() callback infinite loop

前端 未结 5 873
我在风中等你
我在风中等你 2021-02-10 23:54

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

    Either use

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

    or

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

    second case is useful if you want to actually pass some arguments to start..

提交回复
热议问题