从我的 ajax 页面加载中消失的内容有点问题。问题是,它不会淡入,它只是立即显示(延迟后)。
代码:
jQuery(window).on("load", function(){
console.log('document ready');
Initialize();
});
// Initialize all our scripts
function Initialize(){
// Ajax page loading
var $a = jQuery('[data-loadajax="true"]');
var $body = jQuery('.main');
$a.bind('click', function(e){
e.preventDefault();
var $this = jQuery(this);
var $href = $this.attr('href');
$body.fadeOut('slow', function(){
jQuery('#loading').fadeIn('fast');
loadPage($href, $body);
});
});
// Load up the masonry stuff (now checks to see if the grid exists first)
FireExtras();
}
function loadPage(strPageToLoad, strWhereToLoadIt) {
jQuery.ajax({
method: 'post',
url: strPageToLoad,
cache: false,
dataType: "html",
async: true,
data: {'_t':Math.floor(+new Date() / 1000)},
success: function (html) {
// Get just the body
// Get the full HTML of the return
var $html = jQuery(html);
$container = $html.find('.main');
// Get Title
var $title = $html.filter('title').text();
// Get the Meta Description
var $desc = $html.filter('meta[name="description"]').attr('content');
// Get the Meta Keywords
var $keyw = $html.filter('meta[name="keywords"]').attr('content');
// Get the Meta Author
var $auth = $html.filter('meta[name="author"]').attr('content');
// Get the scripts
var $scripts = $html.filter('script');
// Write out the Body
jQuery(strWhereToLoadIt).html($container);
// Hide the pre-loader, and show the body
window.document.title = $title;
jQuery('meta[name=description]').remove();
jQuery('meta[name=keywords]').remove();
jQuery('meta[name=author]').remove();
jQuery('head').append('<meta name="description" content="' + $desc + '">');
jQuery('head').append('<meta name="keywords" content="' + $keyw + '">');
jQuery('head').append('<meta name="author" content="' + $auth + '">');
window.history.replaceState(null, null, strPageToLoad);
//window.location.replace(strPageToLoad);
$scripts.remove();
// Now let's fire up the scripts again, and pull in the appropriate script files...
$scripts.each(function(i){
//$.getScript(this.src);
});
setTimeout(function(){
console.log('Loading...');
jQuery(strWhereToLoadIt).fadeIn(3000, function(){
jQuery('#loading').fadeOut('fast');
FireExtras();
});
}, 10000);
},
error: function () {
console.log('DANGER WILL ROBINSON!');
window.location.href = strPageToLoad;
}
});
}
function FireExtras(){
var menu = new cbpTooltipMenu( document.getElementById( 'cbp-tm-menu' ) );
if(jQuery('#grid').length){
new AnimOnScroll(document.getElementById('grid'), {
minDuration: 0.4,
maxDuration: 0.7,
viewportFactor: 0.2
});
}
}
如何获得内容的success
功能fadeIn
而不是立即显示?
即使是 .delay 也不起作用......