最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What other types are there for the jQuery promise object? - Stack Overflow

programmeradmin6浏览0评论

I've been recently reading about the promise([type] [,target]) function that returns a Promise object.

The documentation states that the default type is fx:

By default, type is "fx", which means the returned Promise is resolved when all animations of the selected elements have pleted.

For some reason I'm having a hard time finding other available types. I assume that other types could be e.g. ajax which gets resolved when content is loaded into a collection using load() or similar methods (note that I know how to handle load() promises, I'm just giving an example).

Is there a list somewhere specifying all available types? I was thinking about looking at the source code to find that out, however I was hoping there is a list somewhere, unless fx is the only sensible type one can use with this function.

I've been recently reading about the promise([type] [,target]) function that returns a Promise object.

The documentation states that the default type is fx:

By default, type is "fx", which means the returned Promise is resolved when all animations of the selected elements have pleted.

For some reason I'm having a hard time finding other available types. I assume that other types could be e.g. ajax which gets resolved when content is loaded into a collection using load() or similar methods (note that I know how to handle load() promises, I'm just giving an example).

Is there a list somewhere specifying all available types? I was thinking about looking at the source code to find that out, however I was hoping there is a list somewhere, unless fx is the only sensible type one can use with this function.

Share Improve this question asked Apr 26, 2013 at 9:42 MMMMMM 7,3102 gold badges26 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

The documentation says about the type argument:

The type of queue that needs to be observed.

By default, all animation functions are added to the fx queue. But with .queue, you can "attach" functions to selected elements which are run in order to a queue of your choice (which you can define).

So, the promise would get resolved once all functions in the specified queue have been called. Though I haven't seen this in practice yet.

Example:

$('div').queue('foo', [function(next) {
    setTimeout(next, 2000); // some delay
}, function(next) {
    console.log('Last function in queue');
    next();
}]).dequeue('foo');

$('div').promise('foo').done(function() {
    console.log('all done');
});

DEMO

发布评论

评论列表(0)

  1. 暂无评论