简体   繁体   English

使用Jquery动画定时Ajax调用

[英]Timing Ajax Calls with Jquery Animations

I'm using the following script to load posts for each user's page. 我正在使用以下脚本为每个用户页面加载帖子。

$.post("postupdate.php", function(data){
var postoutput = $("#postoutput", data);
$("#postcontainer").load("postupdate.php?user=<? echo $profileuser_id; ?> #postoutput");
$( '#postcontainer' ).fadeIn();
}, "html"); 

Everything works fine except the fadeIn function. 除fadeIn功能外,其他所有功能均正常运行。 My load times vary, so sometimes the postcontainer div will fade in before it has been filled with posts from the Ajax Call. 我的加载时间各不相同,因此有时后容器div会在被Ajax Call中的帖子填充之前消失。 How can I control when the fadeIn function goes off so I can make sure it always finishes loading the content before showing the div? 如何控制fadeIn函数何时关闭,以确保在显示div之前始终完成加载内容? It looks really bad right now when they just appear out of thin digital air sometimes. 当它们有时只是凭空出现时,现在看起来真的很糟糕。

-Thanks -谢谢

Use a callback for .load() and do the fade in there. .load()使用回调,然后在其中进行淡入淡出。

$("#postcontainer").load("postupdate.php?user=<? echo $profileuser_id; ?> #postoutput", function(){
    $( '#postcontainer' ).fadeIn();
});

From the documentation: 从文档中:

$("#postcontainer").load("postupdate.php?user=<? echo $profileuser_id; ?> #postoutput", function() {
    $('#postcontainer').fadeIn();
});

.load() has a callback function, either after the data to be sent, or the url. .load()在要发送的数据或URL之后具有回调函数。 This function executes when the loading is complete. 加载完成后执行此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM