1

我有两个一个一个的 jquery 动画:

        books.animate({ left: left1 }, {
            duration: this.slideDuration,
            easing: this.easing,
            complete: complete
        });

        laptops.animate({ left: left2 }, {
            duration: this.slideDuration,
            easing: this.easing,
            complete: complete
        });

我希望动画同时运行,所以我使用{queue: false}

books.animate({ left: left1 }, {
            duration: this.slideDuration,
            easing: this.easing,
                            queue: false,
            complete: complete
        });

        laptops.animate({ left: left2 }, {
            duration: this.slideDuration,
            easing: this.easing,
                            queue: false,
            complete: complete
        });

但是现在完成的回调调用了两次!我怎样才能知道这两个动画是什么时候完成的?

4

4 回答 4

1

为什么不complete从其中一个动画中删除处理程序?

从您发布的代码摘录来看,您似乎在两个动画上使用了相同的持续时间和缓动方法。因此,它们将同时完成本质上是正确的,只要它们同时被调用......

于 2012-11-26T23:00:12.230 回答
1

this may sounds like something complicated, but why not Deferred Objects ?

http://api.jquery.com/category/deferred-object/

you may investigate more here jQuery animation with deferred pipes?

于 2012-11-26T23:02:14.053 回答
1

使用 jQuery 延迟方法尝试

$.when( 
    books.animate({ left: left1 }, {
        duration: this.slideDuration,
        easing: this.easing
    }),
    laptops.animate({ left: left2 }, {
        duration: this.slideDuration,
        easing: this.easing
  })
).done( function( ) {

    alert("done!");

});

在这里提琴

于 2012-11-26T23:13:32.630 回答
0

根据http://darcyclarke.me/development/using-jquery-deferreds-with-animations/

books.animate({ left: left1 }, {
    duration: this.slideDuration,
    easing: this.easing,
    queue: false
});

laptops.animate({ left: left2 }, {
    duration: this.slideDuration,
    easing: this.easing,
    queue: false
});

$.when(books, laptops).done(complete);
于 2012-11-26T23:20:28.797 回答