.wait(deferred ,callback)

Description: Wait for any deferred object to resolve (jQuery, jQuery.Deferred, deferred jQuery chain, …).

deferred – any object with .promise()
e.g. a jQuery selection, a jQuery.Deferred, or another deferred jQuery chain.
callback – function(count…), optional
a method that is called once just before continuing the invocation chain.
All current iteration counts/events (from inner-most to outer-most loop) are passed as arguments.

Tip: You can also wait for the current end of the elements' effect queues via .join().


Examples with waiting for a deferred object

Example #19: pause animation cycle on mouseover

There is a animation cycle rotating three images. Once you move the mouse cursor over it, it pauses until the mouse is moved away.

A little helper function checks whether the mouse is over the image. If that's the case a deferred jQuery object waiting for the mouseleave event is returned.
function noHover() {
    return this.is(':hover') ? this.wait('mouseleave') : this
}

The running loop can be written in a single jQuery line.

$('#images > img').hide().repeat().each($).fadeIn($)
    .wait(1000).wait(noHover).fadeOut($);