jQuery .animate() callback infinite loop

前端 未结 5 646
余生分开走
余生分开走 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:42

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

提交回复
热议问题