我通过ajax调用使用一些html更新div内容,并在加载来自ajax响应的所有图像后执行函数。
请看下面的代码,#gridWrapper来自Ajax响应,它有很多缩略图。
success: function(Data){
MyGrid.prepGridLayout(Data.html);
$('#gridWrapper .thumbnail img').load(function(index) {
MyGrid.updateCellWidth(this);
});
MyGrid.adjustGridWidth();
MyGrid.animateGridLayout();
}我只需要在加载完所有图像之后执行MyGrid.animateGridLayout();。目前,在MyGrid.updateCellWidth(this);执行之前执行MyGrid.animateGridLayout();
如何确保MyGrid.animateGridLayout();仅在加载所有镜像后运行?
发布于 2010-08-03 20:44:04
您可以让“加载”处理程序跟踪它们完成了多少操作。
success: function(Data){
MyGrid.prepGridLayout(Data.html);
var thumbs = $('#gridWrapper .thumbnail img'), tc = 0;
thumbs.load(function(index) {
MyGrid.updateCellWidth(this);
if (++tc === thumbs.length) {
MyGrid.adjustGridWidth();
MyGrid.animateGridLayout();
}
});
}https://stackoverflow.com/questions/3396254
复制相似问题