I have a site which does something similar. The function to slide out, replace content, and slide in is as follows:
var loadAnAjaxArticle = function (url) {
var removeParentArticle = function () {
// I don't like doing this, but so far haven't found a
// particularly elegant way to replace the article
// when calling load(), only append it.
$('article').first().html($('article').last().html());
};
var showArticle = function (response, status, xhr) {
if (status == "error") {
$('article').first().html('<h2>There was an error processing your request.</h2>');
$('article').first().slideDown('slow');
} else {
removeParentArticle();
$('article').first().slideDown('slow');
}
};
var loadArticle = function () {
$('article').first().load(url + ' article', showArticle);
};
$('article').first().slideUp('slow', loadArticle);
}
Basically, it calls .slideUp
to hide the content, providing a call-back to another function. That function calls .load
to refresh the content, providing a call-back to another function. That function does a little manipulation of the DOM to make it look right (it's early in development, I haven't made it more elegant yet), and calls .slideDown
to show the content again.
This is easy to do in this case because each function I'm using accepts a call-back. If the functions you're using have the same capability, you should be able to chain them in this manner.