我使用jquery来fadein,然后使用ajax加载php文件。问题是ajax在div之前加载php文件是可见的,并且足够大。因此,php页面显示在屏幕上,然后在其下加载div。如何减缓php页面的加载速度,或者在div可见后使其可见?Toppi和链接是变量。Toppi包含div位置和链接php页面名。
下面是我使用的代码:
$("#riv1").css("top", + toppi);
$("#riv1").fadeIn();
$("#riv1").animate({height:'600px',opacity:'0.4'},"fast");
$("#riv1").animate({width:'850px',opacity:'0.8'},"fast");
$("#riv1").animate({opacity:'1.0'}, 500);
if (links != '') {
$.ajax({
async:false,
url: links,
cache: false
}).done(function( html ) {
$("#riv1").html(html);
});
}我试过了
$("#riv1").delay(2000).html(html); 但这没什么用。
发布于 2014-01-23 11:53:04
$("#riv1").css("top", + toppi);
$("#riv1").fadeIn();
$("#riv1").animate({height:'600px',opacity:'0.4'},"fast");
$("#riv1").animate({width:'850px',opacity:'0.8'},"fast");
$("#riv1").animate({opacity:'1.0'}, 500,function(){
//calling ajax after animation completed
if (links != '') {
$.ajax({
async:false,
url: links,
cache: false
}).done(function( html ) {
$("#riv1").html(html);
});
}
});完成最后动画后,尝试进行ajax调用。
快乐编码:)
发布于 2014-01-23 11:41:30
尝试将ajax代码放入fadeIn()的回调函数中:
$("#riv1").css("top", + toppi);
$("#riv1").fadeIn("slow",function(){
if (links != '') {
$.ajax({
async:false,
url: links,
cache: false
}).done(function( html ) {
$("#riv1").html(html);
});
}
});
$("#riv1").animate({height:'600px',opacity:'0.4'},"fast");
$("#riv1").animate({width:'850px',opacity:'0.8'},"fast");
$("#riv1").animate({opacity:'1.0'}, 500);只有在fadeIn完成后,ajax函数才会被调用。
发布于 2014-01-23 11:46:11
您可以使用以下函数在jquery请求之前显示加载映像
beforeSend,并且可以像下面这样隐藏加载图像
$.ajax({
beforeSend:function(){
//you logic to add the loading image inside the div
}
async:false,
url: links,
cache: false
}).done(function( html ) {
//Hide the images or replace the div with new content
$("#riv1").html(html);
});https://stackoverflow.com/questions/21307034
复制相似问题