.promise()S2C Home « Objects « .promise()

Promise resolution.

Description

The .promise() Deferred method, returns a dynamically generated Promise that is resolved once all collection bound actions of a certain type have ended.


Syntax

Signature Description
.promise( [type] [, target] )Return a dynamically generated Promise that is resolved once all collection bound actions of a certain type have ended, optionally passing a queue type and/or a target object.

Parameters

Parameter Description Type
type
  • The type of queue that needs to be observed. The default queue is named 'fx' and has certain properties that are not shared with named queues:
    1. The 'fx' queue will automatically .dequeue() the next function on the queue and run it if the queue hasn't started.
    2. When .dequeue() is used on a function from the 'fx' queue, it will unshift() the string 'inprogress', into the [0] location of the array, thus flagging that the 'fx' queue is currently executing.
    3. Being the default, the 'fx' queue is called by .animate() and any other function that calls it by default.
String
targetObject to attach the promise methods to.PlainObject

Return

A Promise object.

.promise( [type] [, target] ) ExamplesTop

Return a dynamically generated Promise that is resolved once all collection bound actions of a certain type have ended, optionally passing a queue type and/or a target object.

In the following example when we press the button the first time, we fire off some animations. We use the .promise() method which gets resolved when all the animations have completed and we display a message.


$(function(){
  $('#btn3').one('click', function(){
    $('#curry1').fadeIn();
    $('#curry2').slideDown('slow').slideUp('fast');
    $('#curry3').fadeIn(2000).fadeOut('fast');
    $('#curry1, #curry2, #curry3').promise().done(function() {
      $('#div1').append('Animations completed!');
    });
  });
});

a picture of curry a picture of curry a picture of curry

Press the button below to action the above code: