Single queue for jQuery animate() elements

后端 未结 3 1187
失恋的感觉
失恋的感觉 2021-01-21 02:53

By default the jQuery queue that is created for animate() is done per element, I\'m wondering if there is a way to create a single queue for all animations done with animate()?

3条回答
  •  余生分开走
    2021-01-21 03:06

    Something like this:

    $(someElement) // could also be a plain object, e.g. $({})
        .queue('customQueue', function (next) {
            first.animate({ ... }, function () {
                // when the animation is complete, call next() for customQueue
                next();
            });
        })
        .queue('customQueue', function (next) {
            second.animate({ ... }, function () {
                // when the animation is complete, call next() for customQueue
                next();
            });
        })
        // add more animations, then
        .dequeue('customQueue');
    

提交回复
热议问题