I don’t know if this technique is wrong but I really only want the new content to be faded in when it’s full loaded. It seems like beforeSend and complete send has no effect in timing. The new content will just fade in even before the slide up has happened,f.e..
I’m not yet quite familiar with ajax you must know.
Here is my code:
$(function(){
var replacePage = function(url) {
$.ajax({
url: url,
type: 'get',
dataType: 'html',
beforeSend: function() {
$(".menue").slideUp();
},
success: function(data){
var dom = $(data);
var html = dom.filter('#content').html();
$('#content').html(html);
},
complete: function(){
$("#content").fadeIn();
}
});
}
$('nav a').live('click', function(e){
history.pushState(null, null, this.href);
replacePage(this.href);
e.preventDefault();
$("#content").hide();
});
$(window).bind('popstate', function(){
replacePage(location.pathname);
});
});
Try the following:
or you can use
slideUp()‘s callback function which executes after animation is complete:note that
live()is deprecated and you can useon()method instead.