I think it's as simple as this :
(function($) {
$.fn.ajaxTransitionOut = function() {
return this.find('.animate').each(function() {
$(this).animate({
left: 500,
opacity: 0
}, 4000);
});
};
})(jQuery);
$.when($('#content').ajaxTransitionOut()).done(function() {
$('html').css('backgroundColor','#999');
});
Fiddle - http://jsfiddle.net/hrm6w/8/
You will see I changed the constants and the terminal action to better observe the process.
I confess I don't fully understand why this works but it appears that a composite promise for all selected elements is implicit in the jQuery object returned by the plugin (and thus made available to .done()
down the method chain).
I expect this only works because we are dealing with animations and a promise's default type
is 'fx' (see documentation for .promise()).
Edit:
You can alternatively drop .when()
and generate an explicit promise with .promise()
in the method chain like this :
$('#content').ajaxTransitionOut().promise().done(function() {
$('html').css('backgroundColor','#999');
});
The plugin remains the same.