I'm trying to get my head around the whole deferred concept and I'm trying to use it to synchronize a fadeIn/fadeOut animation together with an Ajax call.
Basically I'm switching content on page doing:
- Fetch content with ajax
- On response FadeOut
- Replace content
- FadeIn
However, If i understand deferreds right I might be able to do something like this:
- fadeOut, and at the same time initialize Fetch content with ajax
- When both the fadeOut and the Fetch content are complete: Change content
- FadeIn
Some code of the original solution:
$.get(url, function(page) {
    $('#content').fadeTo(100, 0, 'linear', function() {
        $(this).html(page.text).fadeTo(400, 1, 'linear');
    });
}
I am trying to do something like this:
var deferred1 = $.get(url);
var deferred2 = $('#content').fadeTo(100, 0, 'linear').promise();
$.when(deferred1, deferred2).done(function() {
    $('#content').html(page.text).fadeTo(400, 1, 'linear');
});
I just can't really get clear on how to use it. And should i use done or then? Should I use pipe in a clever way? Do I need promise?
What would be the more 'standardized' way to implement this?
 
     
    