animate在完成之前触发回调

时间:2015-07-30 22:10:22

标签: javascript jquery

我使用动画功能

    var square = $('<div class="square"></div>');
    $('body').append(square);

    square.css({
        'background-color': 'red',
        'top': '10px',
        'left': '10px'
    }).animate({
        left: left + 'px',
        top: top + 'px'
    }, {
        duration: 400,
        complete: callback
    });

它在实际完成之前触发回调

我必须做一个解决方法

回调函数中的

我使用setTimeout让它等待400秒。但是为什么我无法动画调用回调函数完成它?

1 个答案:

答案 0 :(得分:0)

将完成回调作为第三个参数传递

square.css({
    'background-color': 'red',
    'top': '10px',
    'left': '10px'
}).animate({
    left: left + 'px',
    top: top + 'px'
}, 400, callback);

http://api.jquery.com/animate/

相关问题