jQuery .promise()Method

jQuery 杂项方法jQuery Miscellaneous Methods

Examples

Call .promise() on a collection with no active animations

$(function () { var div = $( "<div />" ); div.promise().done(function( arg1 ) { //Alert "true" alert( this === div && arg1 === div ); }); })

Try it »

Definition and Usage

The .promise() function returns a Promise object that observes whether all actions of a certain type bound to the collection have been added to the queue.


Note:1. The .promise() method returns a dynamically generated Promise. When all specific actions (actions) bound to the collection have been added to the queue or have not been added to the queue, the generated Promise will be resolved.
2. The default value of type is "fx", which means the resolved Promise object is returned when all animations of the selected elements have completed.
3. If the target parameter is provided, .promise() adds methods onto that parameter and returns this object, rather than creating a new one. This is useful for adding Promise behavior to an existing object.


Syntax

.promise( [type ] [, target ] )

Parameters Description
type String - The type of queue to be observed.
target PlainObject - The object onto which the promise methods will be added.


实例

More Examples

Resolve the returned Promise when animations end
When all animations have ended (including those initialized in animation callback functions and in callbacks added afterwards), resolve the returned Promise.

Use the $.when() statement to resolve the returned Promise
Use the $.when() statement (the .promise() method makes it possible to implement it in a jQuery collection) to resolve the returned Promise.


jQuery 杂项方法jQuery Miscellaneous Methods

Other Extensions